MySQL database cleanup MyISAM Innodb table (MySQL versions earlier than MySQL 5.1.6 are supported)

Source: Internet
Author: User

There are a large number of MyISAM log tables in the data center that need to be cleaned regularly. This is set to be done every weekend, about 10 Gb, 5-10 minutes.
The event will not be written here, And the stored procedure will be directly stored ....
[SQL] view plaincopyprint?
Drop procedure if exists proc_optable;
Tudou @ gyyx
2012-02-22
Create procedure proc_optable ()
BEGIN
DECLARE dono int default 0;
DECLARE o VARCHAR (2000 );
DECLARE optable CURSOR
FOR
Select concat ('optimize table'', TABLE_SCHEMA ,''. '', TABLE_NAME,''; ') from information_schema. 'tables' WHERE TABLE_TYPE = 'base table' and engine in ('myisam', 'innodb', 'bdb ');
Declare continue handler for not found set dono = 1;
SET dono = 0;
OPEN optable;
REPEAT
FETCH optable INTO o;
Set @ o = o;
Prepare msql from @ o;
Execute msql;
UNTIL dono end repeat;
 
CLOSE optable;
END


From the column of ylqmf

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.