Large table Batch Delete script MySQL version

Source: Internet
Author: User
Tags mysql version

It is often necessary to periodically delete historical data from certain tables, which are often very large, and in order to mitigate the impact on the online environment, they must be deleted in small batches.

Previously shared version of SQL Server.

Here is the MySQL version:

1 delimiter $$2 Drop procedure if existsProc_delete_old_data;3 Create procedureProc_delete_old_data ()4 begin5 Lp:loop6     Delete  fromMyTablewhereCreatedtime<=Date_sub (Curdate (), Interval1 Month) limit the;7     ifRow_count ()<  the  Then8 leave LP;9     End if;Ten     SelectSleep1); One EndLoop; A End $$ -  - delimiter; the SetBinlog_format=STATEMENT; -Call Proc_delete_old_data;

This address: http://www.cnblogs.com/ajiangg/p/6604317.html

Large table Batch Delete script MySQL version

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.