Skip to content

hcymysql/update_10w

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

update_10w

循环分批次批量更改数据10万行记录

业务方的SQL: UPDATE t1 SET report_status=0 WHERE create_time>'2022-04-28 00:00:00' and create_time<'2022-04-29 00:00:00';

这个SQL要改18422654条数据,直接执行会影响业务稳定性,并且造成主从复制延迟。

第一种思路:

固需要通过脚本,循环分批次批量更改数据10万行记录。

shell> yum install php php-mysqlnd -y

shell> php update_10w.php

image

第二种思路:

1)先把主键id导出到临时文件里。

mysql> select id from sbtest1 order by id asc into outfile '/tmp/sbtest1.txt' FIELDS TERMINATED BY ',';

2)固需要通过脚本,循环分批次批量更改数据10万行记录。

shell> pip3 install PyMySQL -i "http://mirrors.aliyun.com/pypi/simple" --trusted-host "mirrors.aliyun.com"

shell> python3 update_10w.py

About

循环分批次批量更改数据10万行记录

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published