Batch Delete scripts for large tables: MySQL version; Delete scripts for mysql

Source: Internet
Author: User

Batch Delete scripts for large tables: MySQL version; Delete scripts for mysql

It is often necessary to regularly Delete historical data from some tables. The data in such tables is usually very huge. To reduce the impact on the online environment, the deletion must be divided into small batches.

I have previously shared the SQLServer version.

The following is the MySQL version:

1 delimiter $2 drop procedure if exists proc_delete_old_data; 3 create procedure proc_delete_old_data () 4 begin 5 lp: loop 6 delete from mytable where createdtime <= date_sub (curdate (), interval 1 month) limit 5000; 7 if row_count () <5000 then 8 leave lp; 9 end if; 10 select sleep (1); 11 end loop; 12 end $13 14 delimiter; 15 set binlog_format = STATEMENT; 16 call proc_delete_old_data;

Address: http://www.cnblogs.com/ajiangg/p/6604317.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.