针对增 删 改操作 执行重要程度偏高
你如果真想操作 必须有一步确认操作(commit)
import pymysql
conn = pymysql.connect(
user = 'root',
passwd = '123456',
db = 'day36',
host = '127.0.0.1',
port = 3306,
charset = 'utf8',
autocommit = True # 自动提交确认
)
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
# #查: 获取用户输入的用户名和密码 然后取数据库中校验
# username = input('username>>>:').strip()
# password = input('password>>>:').strip()
# # sql = "select * from userinfo where name='%s' and password= '%s'"%(username,password)
# sql = "select * from userinfo where name=%s and password= %s"
# print(sql)
# 增
sql = "insert into userinfo(name,password,dep_id) values('jason',789,1)"
# 改
# sql = "update userinfo set name='egondsb' where id = 6"
# 删除
# sql = "delete from userinfo where id= 1"
res = cursor.execute(sql)
# conn.commit() # 确认当前操作 真正的同步到数据库
print(res)
以上就是相关知识点内容,感谢大家的学习和对的支持。
更多Mysql内容来自木庄网络博客
标签:Mysql
相关阅读 >>
mysql 5.7.18 利用mysql proxies_priv实现类似用户组管理实例分享
更多相关阅读请进入《mysql》频道 >>
数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。