python executemany
作者:互联网
#coding:utf8
conn = MySQLdb.connect(host = “localhost”, user = “root”, passwd = “123456”, db = “myDB”)
cursor = conn.cursor()
sql = “insert into myTable (created_day,name,count) values(%s,%s,%s) ON DUPLICATE KEY UPDATE count=count+values(count)”
args=[("2012-08-27","name1",100),("2012-08-27","name1",200),("2012-08-27","name2",300)]
try:
cursor.executemany(sql, args)
except Exception as e:
print0(“执行MySQL: %s 时出错:%s” % (sql, e))
finally:
cursor.close()
conn.commit()
conn.close()
标签:count,27,python,08,cursor,executemany,conn,2012 来源: https://blog.csdn.net/luoganttcc/article/details/120571251