码迷,mamicode.com
首页 > 数据库 > 详细

mysql 批量删数据并且整理表碎片

时间:2018-11-02 16:39:48      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:RoCE   info   orm   nis   ati   for   format   not   mat   

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

mysql 批量删数据并且整理表碎片

标签:RoCE   info   orm   nis   ati   for   format   not   mat   

原文地址:http://blog.51cto.com/1937519/2312248

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!