DROP PROCEDURE IF EXISTS prc_del_loop;
CREATE PROCEDURE prc_del_loop()
BEGIN
DECLARE v_count INT ;
DECLARE v_data_free INT;
my_del_loop:LOOP
delete from t_data where adress = ‘苏州日志分析苏州日志分析‘ limit 10000;
select count(1) into v_count from (
select * from t_data where adress = ‘苏州日志分析苏州日志分析‘ limit 1 ) d;
IF v_count=0 THEN
LEAVE my_del_loop;
END IF;
END LOOP my_del_loop;
SELECT "TABLE DATA HAS DELETED !!!";
#整理碎片,data_free大于等于100M进行整理
select round(sum(data_free/1024/1024),0) into v_data_free
from information_schema.tables where TABLE_SCHEMA= ‘data‘ and table_name = ‘t‘;
IF v_data_free >=100 THEN
SELECT "TABLE SHRINK IS RUNNING!!!";
alter table t ENGINE=INNODB;
SELECT "TABLE SHRINK IS FINISHED!!!";
ELSE
SELECT "TABLE SHRINK IS NOT NEED SHRINK!!!";
END IF;
END
原文地址:http://blog.51cto.com/1937519/2312248