pymysql 写入数据

import pymysql.cursors
#连接配置信息
config = {
'host':'127.0.0.1',
'port':3306,
'user':'root',
'password':'08300734',
'db':'db',
'charset':'utf8',
'cursorclass':pymysql.cursors.DictCursor,
}
# 创建连接
connection = pymysql.connect(**config)
cursor = connection.cursor()

sql = "INSERT INTO `tab1` (`city`, `region`,`name`) VALUES ('shanghai', 'changnin','xinjinbeiyuan')"
cursor.execute(sql)

connection.commit()
posted @ 2018-06-19 22:27  luoganttcc  阅读(230)  评论(0编辑  收藏  举报