光说有毛用


python mysql 2014 error

· by admin · Read in about 1 min · (57 Words)
python error mysql 

###python mysqlDB批量插入数据时报错

python MySQLdb module error code:

Error 2014: Commands out of sync; you can't run this command now

This happened when excute mysql batch operation. Solution:

Every mysql option done, then call commit()

Using executemany funcion is recommand.

list = []
sql = 'INSERT INTO tablexxx(a,b,c) VALUES(%s,%s,%s)'
for l in ll:
    list.append(l)
db.executemany(sql, list)#db.fetchmany() ...
db.commit()

Comments