Python操作MySQL批量更新语句connection = t(user='root',password='mysql',database='test',host='127.0.0.1',port=3306,charset='utf8mb4') name_lit =["re","gh","ds","D"]# 存储name的值
age_lit =["10","20","30","40"]# 存储age的值
id_lit =["1","2","3","4"]# 存储id的值
lit =[[name_lit[i],age_lit[i],id_lit[i]]for i in range(len(id_lit))]
print(lit)
with connection.cursor()as cursor:
try:
sql ="update test SET name=(%s), age=(%s) where id=(%s)"
connectionmit()
except:
connection.close()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论