DELIMITER $$
DROP PROCEDURE IF EXISTS `study`.`xx` $$
CREATE PROCEDURE `study`.`xx` ()
BEGIN
DECLARE i int;
loop1:loop
delete from xxx where xx=xx limit 5000;
select row_count() into i;
if i=0 then
leave loop1;
end if;
select sleep(1);
end loop loop1;
END $$
DELIMITER ;
分批删除数据减少对undo段的使用(mysql有个线程purge会定时回收空闲的undo)。