使用python连接mysql数据库时,如果遇到这样的错误提示:

(2014, "Commands out of sync; you can't run this command now")

可能是你的几条sql语句执行顺序有问题,也有可能是cursor本身的bug。

在执行sql语句前最好清空 cursor里面的所有内容。

def executeNonQuery(cursor, sql):
    while cursor.nextset(): pass
    cursor.execute(sql)

这样就没有问题了
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐