#coding=utf-8
import MySQLdb
import datetime
db = MySQLdb.connect("localhost","root","123456","test",charset = 'utf8')
cursor = db.cursor()
sql="sql语句"
try:
# 执行sql语句
cursor.execute(sql)
# 提交到数据库执行
db.commit()
except:
# Rollback in case there is any error
db.rollback()
# 关闭数据库连接
db.close()
print("添加数据到mysql成功了")
print(datetime.datetime.now())
python2 往mysql插入数据
猜你喜欢
转载自blog.csdn.net/xxmonstor/article/details/80855039
今日推荐
周排行