当前位置:首页>python>python操作mysql数据库增删改查

python操作mysql数据库增删改查

  • 2026-09-10 22:32:18
python操作mysql数据库增删改查

中国计算机技术交流群共同交流学习,来的加我微信拉你进群958038508

import pymysql

username = input('please intput username: ').strip()

old_password = input('please input old password: ').strip()

new_password = input('please input new password: ').strip()

con_sql = pymysql.connect(host='192.168.168.131', port=3306, user='root', passwd='admin', db='logininfo')

cursor = con_sql.cursor()

#增加

#sql = f'insert into login(username, password) values("{username}", "{password}");'

#cursor.execute(sql)

#con_sql.commit()

#---------------------------------------------------------------------

#查询

#sql = f'select * from login where username="{username}" and password="{password}";'

#cursor.execute(sql)

#con_sql.commit()

#result = cursor.fetchall()

#if bool(result) == 1:

# print('登陆成功')

#else:

# print('登陆失败')

#---------------------------------------------------------------------

#删除

#sql = f'delete from login where username="{username}" and password="{password}";'

#cursor.execute(sql)

#con_sql.commit()

#---------------------------------------------------------------------

#更新

sql = f'update login set password = "{new_password}" where username = "{username}" and password = "{old_password}";'

cursor.execute(sql)

con_sql.commit()

cursor.close()

con_sql.close()

中国计算机技术交流群共同交流学习,来的加我微信拉你进群958038508

最新文章

随机文章