MySql教程

pymysql操作数据更新

本文主要是介绍pymysql操作数据更新,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import  pymysql
list=['anhui', 'beijing', 'chongqing', 'fujian', 'gansu', 'guangdong', 'guangxi', 'guizhou', 'hainan', 'hebei', 'heilongjiang', 'henan', 'hubei', 'hunan', 'jiangsu', 'jiangxi', 'jilin', 'liaoning', 'neimenggu', 'ningxia', 'qinghai', 'shaanxi', 'shandong', 'shanghai', 'shanxi', 'sichuan', 'tianjing', 'xinjiang', 'xizang', 'yunnan', 'zhejiang']
for i in list:
    print(i)
    conn = pymysql.connect(host='localhost',port=3306,user='root',password='123456',database='zsz')
    cursor = conn.cursor()
    sql3= 'update '+i+' set rate=AJS/A where Time between 2010.0 and 2021.0;'
    try:
        cursor.execute(sql3)
        print(‘执行成功’)
        conn.commit()
    except Exception as e:
        conn.rollback()
    finally:
        conn.close()

 

这篇关于pymysql操作数据更新的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!