import pymysql
# username = input(‘请输入用户名:‘)
# pwd = input(‘请输入密码:‘)
# 1.连接
conn = pymysql.connect(host=‘localhost‘, port=3306, user=‘root‘, password=‘zx360828htc‘, db=‘test‘, charset=‘utf8‘)
# 2.创建游标
cursor = conn.cursor()
# 操作
# 增
# sql = "insert into userinfo(username,pwd) values (%s,%s)"
# effect_row = cursor.execute(sql,(username,pwd))
#同时插入多条数据
#cursor.executemany(sql,[(‘李四‘,‘110‘),(‘王五‘,‘119‘)])
# print(effect_row)#
# 改
# sql = "update userinfo set username = %s where id = 2"
# effect_row = cursor.execute(sql,username)
# print(effect_row)
# 删
sql = "delete from movie where movieid = 2"
effect_row = cursor.execute(sql)
print(effect_row)
#一定记得commit
conn.commit()
# 4.关闭游标
cursor.close()
# 5.关闭连接
conn.close()
pymysql的增删改操作