通过python优化mysql插入查询

时间:2016-03-04 20:58:58

标签: python mysql

db = MySQLdb.connect(host="xxx.xx.xx.x",   
                    user="xxx",       
                    passwd="xxx",  
                    db="xxxx")
for loop on json data:
    cursor = db.cursor()
    cursor.execute('Insert Query')
    db.commit() 
db.close()

我可以改进此查询吗?我正在考虑在db.commit()

之前做多个cursor.execute

我不确定db.commit()的工作原理及其重要性。

我基本上是循环json数据并用循环插入它。我无法避免多次插入。

1 个答案:

答案 0 :(得分:1)

根据$ ps -o %cpu,comm %CPU COMM 0.0 /opt/boxen/homebrew/Cellar/erlang/18.0.3/lib/erlang/erts-7.0.3/bin/beam.smp 的结构,您应该可以使用.executemany()

json_data