pymysql的增删改

import pymysql
username=input('请输入用户名:')
pwd=input('请输入密码:')
pymysql.connect()
# 创建连接
conn=pymysql.connect(
    host='127.0.0.1',
    # localhost
    user='root',
    password='',
    database='db2',
    port=3306,
    charset='utf8'
)
# 创建游标
cur=conn.cursor()
sql = "insert into userinfo(name,pwd) values (%s,%s)"
print(sql)
res=cur.execute(sql,[username,pwd])
print(res)
# 增,删,改 一定要加commit
conn.commit()
# 关闭游标
cur.close()
conn.close()

 

posted @ 2019-08-30 16:59  你我皆牛马  阅读(162)  评论(0编辑  收藏  举报