Python 根据条件 更新MySQL数据库字段数据

时间:2020-09-17 13:25:32   收藏:0   阅读:41
# 导入MySQL
import pymysql

# 连接数据库
conn = pymysql.connect(host="111.111.111.111", user="11111", password="1111111", port=3306, db="11111",charset="utf8")

# 创建游标
cursor = conn.cursor()

"""根据last_sync_time字段更新数据为“2020-8-30 23:35:23”"""
# 语法为:" update 表名 set 字段 = ‘ 要更改的数据‘"
sql = "update t_car_detail_city set last_sync_time = ‘2020-8-30 23:35:23‘"

#  执行sql语句
cursor.execute(sql)
#  提交操作
conn.commit()
cursor.close()  # 关闭游标
conn.close()  # 关闭连接

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!