Loading

python中pymysql使用

python中pymysql使用

https://blog.csdn.net/johline/article/details/69549131

 

import pymysql

# 连接数据库
connect = pymysql.Connect(host='localhost',
                          port=3306, user='root',
                          password='root', db='trademark',
                          charset='utf8')

# 获取游标
cursor = connect.cursor()

# 插入数据
sql = "insert into tm_trademark (name) values('%s')"
data = ('name01',)
cursor.execute(sql % data)
connect.commit()

cursor.close()
connect.close()

 

posted @ 2018-04-30 18:33  stono  阅读(149)  评论(0编辑  收藏  举报