import pymysql
try:
#首先要链接mysql
db=pymysql.connect("127.0.0.1","root","1234")
#数据的游标
cursor=db.cursor()
#选择数据库
cursor.execute("use test")
#增加数据
#cursor.execute("insert into leibusi values(8,'chen',88888)")
#删除数据
#cursor.execute("delete from leibusi where username='ssss'")
#查询数据
#cursor.execute("select * from leibusi")
#修改数据
cursor.execute("update leibusi set username='wang' where username='tun'")
#使sql语句生效
db.commit()
#关闭mysql链接
db.close()
print("密码正确")
except:
print("密码错误")
Python操作Mysql数据库
最新推荐文章于 2024-07-20 18:48:57 发布