版权声明:版权归本人,仅供大家参考 https://blog.csdn.net/Dream____Fly/article/details/86655880
修改数据:
import pymysql
config = {
'host':'localhost',
'port':3306,
'user':'root',
'passwd':'root',
'db':'logon',
'charset':'utf8'
}
# 打开数据库连接
conn = pymysql.connect(**config)
try:
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = conn.cursor()
# SQL 更新语句
sql = "UPDATE EMPLOYEE SET AGE = AGE + 1 " \
"WHERE SEX = '%c'" % ('M')
# 执行SQL语句
cursor.execute(sql)
# 确认修改
conn.commit()
# 关闭游标
cursor.close()
# 关闭链接
conn.close()
print("修改成功")
except:
print("修改失败")