当前位置:Gxlcms > mysql > MySQL数据库清理MyISAMInnodb表(支持MySQL5.1.6以上的版本)_MySQL

MySQL数据库清理MyISAMInnodb表(支持MySQL5.1.6以上的版本)_MySQL

时间:2021-07-01 10:21:17 帮助过:22人阅读

bitsCN.com 数据中心有大量的MyISAM log表需要定时清理,定为每周末,10G左右,5-10分钟完成.
event 调用这里就不写了,直接上存储过程....
[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


摘自 ylqmf的专栏 bitsCN.com

人气教程排行