大表分批刪除指令碼之MySQL版

來源:互聯網
上載者:User

標籤:font   bin   oop   form   stat   sql   call   server   creat   

經常需要定期對某些表刪除曆史資料,通常這樣的表的資料又是非常巨大,為了減輕對線上環境的影響,刪除時必須分成小批量來進行。

以前分享過SQLServer的版本。

下面是MySQL版本:

 1 delimiter $$ 2 drop procedure if exists proc_delete_old_data; 3 create procedure proc_delete_old_data() 4 begin 5 lp : loop 6     delete from mytable where createdtime <= date_sub(curdate(),interval 1 month) limit 5000; 7     if row_count() < 5000 then 8         leave lp; 9     end if;10     select sleep(1);11 end loop;12 end $$13 14 delimiter ;15 set binlog_format = STATEMENT;16 call proc_delete_old_data;

本文地址:http://www.cnblogs.com/ajiangg/p/6604317.html

大表分批刪除指令碼之MySQL版

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.