IT虾米网

mysql 批量删除

luoye 2018年06月24日 数据库 922 0
CREATE PROCEDURE  del_line() 
 
BEGIN  
 
      DECLARE count_line INT; 
 
        /** 先删除索引提高删除速度*/ 
 
ALTER TABLE `test_road_1`.`lebp_logistics_line`   
 
DROP INDEX index_carrier_id, 
 
DROP INDEX index_state, 
 
DROP INDEX index_leave_city, 
 
DROP INDEX index_leave_city_area, 
 
DROP INDEX index_arrive_city, 
 
DROP INDEX index_arrive_city_area, 
 
DROP INDEX index_mock_attachment; 
 
SELECT COUNT(*) INTO count_line FROM lebp_logistics_line; 
 
WHILE count_line > 0 DO  
 
   DELETE FROM lebp_logistics_line LIMIT 10000 ; 
 
   COMMIT ; 
 
   SET count_line = count_line - 10000 ; 
 
END WHILE ; 
 
END

评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!