Python的mysql数据库的更新如何实现
作者:cakin24 时间:2024-01-28 13:43:12
Python的mysql数据库的更新
Python的mysql数据库的更新操作,在实际应用项目中会用到更新数据库,更新过程中可能会出现数据丢失或者数据错乱等系统性的问题,还希望大家正确操作,
一 代码
import pymysql
# 打开数据库连接
db = pymysql.connect("localhost","root","root","db_test01" )
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# SQL 更新语句
sql = "UPDATE EMPLOYEE SET AGE = AGE + 1 WHERE SEX = '%c'" % ('M')
try:
# 执行SQL语句
cursor.execute(sql)
# 提交到数据库执行
db.commit()
print("update OK")
except:
# 发生错误时回滚
db.rollback()
# 关闭数据库连接
db.close()
二 运行结果
update OK
来源:http://cakin24.iteye.com/blog/2386682
标签:Python,数据库,更新
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python turtle绘画象棋棋盘
2022-05-06 22:48:55
![](https://img.aspxhome.com/file/2023/4/86374_0s.jpg)
Python UI自动化测试Web frame及多窗口切换
2023-05-29 01:18:55
Python实现点云投影到平面显示
2021-05-10 14:51:15
Python OpenCV招商银行信用卡卡号识别的方法
2022-01-16 06:31:30
![](https://img.aspxhome.com/file/2023/5/83785_0s.jpg)
ECharts框架分段视觉映射在移动端适配
2024-04-28 09:53:49
![](https://img.aspxhome.com/file/2023/0/132700_0s.png)
Django ValuesQuerySet转json方式
2021-12-05 07:15:34
纯ASP结合VML生成完美图-饼图
2010-05-11 16:49:00
详解Python的循环结构知识点
2021-09-30 11:42:03
Python常见数据结构详解
2021-10-28 22:07:33
浅谈numpy中np.array()与np.asarray的区别以及.tolist
2022-06-06 12:32:10
![](https://img.aspxhome.com/file/2023/7/70697_0s.jpg)
SQL实现查询某字段的值为空的记录
2024-01-18 13:44:56
![](https://img.aspxhome.com/file/2023/7/96227_0s.jpg)
javascript事件冒泡,事件捕获和事件委托详解
2024-04-10 14:02:47
TensorFlow中tf.batch_matmul()的用法
2022-06-06 10:33:37
django实现图片上传数据库并显示
2024-01-13 08:52:24
vue项目base64字符串转图片的实现代码
2024-04-30 10:21:46
![](https://img.aspxhome.com/file/2023/8/130258_0s.png)
python中apply函数详情
2023-06-03 14:58:15
![](https://img.aspxhome.com/file/2023/1/87941_0s.png)
python进阶教程之模块(module)介绍
2021-06-16 12:52:07
Python面向对象编程中关于类和方法的学习笔记
2023-07-20 00:13:37
switchery按钮的使用方法
2024-04-29 13:40:44
![](https://img.aspxhome.com/file/2023/3/132593_0s.png)
JQuery对ASP.NET MVC数据进行更新删除
2024-06-05 09:32:05
![](https://img.aspxhome.com/file/2023/4/122784_0s.png)