#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()
相关文章
- 10-05python 将汉字转换为拼音
- 10-05猜数字游戏Python
- 10-05Python代码实现猜数字游戏
- 10-05python基础 day1 var、 if、while、for、with as、open用法
- 10-05Python中的深浅拷贝
- 10-05python学习总结_1
- 10-05python入门学习第三天,变量,ifelse语句
- 10-05python基础-循环
- 10-05Python3.x 基础练习题100例(91-100)
- 10-05python学习笔记