2023年8月3日发(作者:)

pythonmysql⼤量update_Python批量updateMySQL数据库表某字段import pymysql#链接数据库conn=t(host='127.0.0.1',user='***',passwd='***',db='***',port=3306,charset='utf8')#批量update函数def Item_Clean_Spu(item_combine_spu_re):item_clean_spu_id=item_combine_spu_re[['id','spu_id']]item_clean_spu_id=item_clean_spu_id[item_clean_spu_id['spu_id'].notnull()]item_clean_spu_id=item_clean_spu__index(drop=True)for i in (len(item_clean_spu_id)+2)[1:-1]:sql="""update item_clean ic set _id = {0}where _id={1} and _id IS NULL""".format(item_clean_spu_id[:i]['spu_id'].astype(str).tolist()[(i-1)],item_clean_spu_id[:i]['id'].astype(str).tolist()[(i-1)])(reconnect=True)sqled= (sql)()采取了低效的for循环,有更好的⽅式欢迎告知,感谢~~还发现⼀个⼩问题,⼀个报错:1205 - Lock wait timeout exceeded; try restarting transaction,结果是同事在改动表hiahiahia,我还傻乎乎找了半天搞了半天数据库,kill⼀堆线程,还是要多多学习鸭~

2023年8月3日发(作者:)

pythonmysql⼤量update_Python批量updateMySQL数据库表某字段import pymysql#链接数据库conn=t(host='127.0.0.1',user='***',passwd='***',db='***',port=3306,charset='utf8')#批量update函数def Item_Clean_Spu(item_combine_spu_re):item_clean_spu_id=item_combine_spu_re[['id','spu_id']]item_clean_spu_id=item_clean_spu_id[item_clean_spu_id['spu_id'].notnull()]item_clean_spu_id=item_clean_spu__index(drop=True)for i in (len(item_clean_spu_id)+2)[1:-1]:sql="""update item_clean ic set _id = {0}where _id={1} and _id IS NULL""".format(item_clean_spu_id[:i]['spu_id'].astype(str).tolist()[(i-1)],item_clean_spu_id[:i]['id'].astype(str).tolist()[(i-1)])(reconnect=True)sqled= (sql)()采取了低效的for循环,有更好的⽅式欢迎告知,感谢~~还发现⼀个⼩问题,⼀个报错:1205 - Lock wait timeout exceeded; try restarting transaction,结果是同事在改动表hiahiahia,我还傻乎乎找了半天搞了半天数据库,kill⼀堆线程,还是要多多学习鸭~