Python MySQLdb从一个文件执行多个语句而不进行解析

Python MySQLdb从一个文件执行多个语句而不进行解析,python,mysql-python,Python,Mysql Python,是否可以使用Python mysqldb库应用MySQL批处理文件。到目前为止,我试图“执行”文件的内容: cur = connection.cursor() cur.execute(file(filename).read()) cur.commit() # and without commit 这只适用于一条语句。否则我会得到错误: Failed to apply content. Error 2014: Commands out of sync; you can't run this co

是否可以使用Python mysqldb库应用MySQL批处理文件。到目前为止,我试图“执行”文件的内容:

cur = connection.cursor()
cur.execute(file(filename).read())
cur.commit() # and without commit
这只适用于一条语句。否则我会得到错误:

Failed to apply content. Error 2014: Commands out of sync; you can't run this command now

我打算支持任何类型的MySQL模式,表会改变,所以逐行解析文件不是一个选项。除了从Python调用mysql客户端,还有其他解决方案吗?

我想您使用的是cx\U oracle? 该问题是由于在游标中调用了不存在的方法,而在连接中应该调用该方法。 应该是的

    cur = connection.cursor()
    cur.execute(file(filename).read())
    connection.commit()

在文件(filename.read().split(“;”):cur.execute(statement)?谢谢。这对于简单的语句肯定有效,但我不想解析文件。如果我能帮忙的话,我不想弄乱文件的结构。现在我可以直接调用mysql客户端,但我认为有更好的方法。