Giter Site home page Giter Site logo

update_10w's Introduction

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

update_10w's People

Contributors

hcymysql avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

yuanduobao

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.