现有一文件,其中存储大量 sql 语句,操作多个表,需要 python 读取并执行。
使用 mysqlclient 库,似乎只能一次执行一条语句,执行 100 条语句需要 100 次网络通信;
如果将语句用分号连接,调用 cursor.execute 会报:
MySQLdb._exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now")
cursor.executemany 方法只能对同一个表进行插入,不适用多表的情形。并且查看 executemany 的源码发现也是逐条请求的。
请问,一次网络请求执行多条 sql 语句,能否实现?