批量删除2000w数据
使用delete from table太慢
i i<span style=”color: #0000ff;”>while i<span style=”color: #808080;”><<span style=”color: #800000; font-weight: bold;”>2001<span style=”color: #000000;”>
DO
<span style=”color: #0000ff;”>DELETE <span style=”color: #0000ff;”>FROM f_log
<span style=”color: #0000ff;”>WHERE (id
<span style=”color: #808080;”>><span style=”color: #800000; font-weight: bold;”>95000000) <span style=”color: #0000ff;”>ORDER <span style=”color: #0000ff;”>BY id
LIMIT <span style=”color: #800000; font-weight: bold;”>10000<span style=”color: #000000;”>;
<span style=”color: #0000ff;”>SELECT SLEEP(<span style=”color: #800000; font-weight: bold;”>0.5<span style=”color: #000000;”>);
<span style=”color: #0000ff;”>set i<span style=”color: #808080;”>=i<span style=”color: #808080;”>+<span style=”color: #800000; font-weight: bold;”>1<span style=”color: #000000;”>;
<span style=”color: #0000ff;”>end <span style=”color: #0000ff;”>while<span style=”color: #000000;”>;
<span style=”color: #0000ff;”>END<span style=”color: #000000;”>;
<span style=”color: #808080;”>//<span style=”color: #000000;”>DELIMITER
CALL deleteManyTable();
参考文献:
http://mysql.rjweb.org/doc.php/deletebig