mysql快速删除大表数据部分数据_mysql删除大表的部分数据
mysql刪除大表的部分?jǐn)?shù)據(jù)
好久沒寫博客。最近項(xiàng)目要上線。下班時(shí)間還得陪著老媽。實(shí)在沒時(shí)間更新。
今天有人提了一個(gè)問題, ?www.2cto.com
一個(gè)表有1億6000萬的數(shù)據(jù),有一個(gè)自增ID。最大值就是1億6000萬,需要?jiǎng)h除大于250萬以后的數(shù)據(jù),有什么辦法可以快速刪除?
當(dāng)時(shí)看了一眼數(shù)據(jù)嚇尿了,這么大的數(shù)據(jù)要?jiǎng)h除到什么時(shí)候啊,最要命的鎖表腫么辦
delete是不行了,加索引也別想。mysql上delete加low_priorty,quick,ignore估計(jì)也幫助不大
看到mysql文檔有一種解決方案:https://dev.mysql.com/doc/refman/5.0/en/delete.html
If you are deleting many rows from a large table, you may exceed the lock table size for an InnoDB table. To avoid this problem, or simply to minimize the time that the table remains locked, the following strategy (which does not use DELETE at all) might be helpful:
Select the rows not to be deleted into an empty table that has the same structure as the original table:
INSERT INTO t_copy SELECT * FROM t WHERE ... ;
Use RENAME TABLE to atomically move the original table out of the way and rename the copy to the original name:
RENAME TABLE t TO t_old, t_copy TO t;
Drop the original table:
DROP TABLE t_old;
E文不好,簡(jiǎn)單的翻譯下:
刪除達(dá)標(biāo)上的多行數(shù)據(jù)時(shí),innodb會(huì)超出lock table size的限制,最小化的減少鎖表的時(shí)間的方案是:
1選擇不需要?jiǎng)h除的數(shù)據(jù),并把它們存在一張相同結(jié)構(gòu)的空表里
2重命名原始表,并給新表命名為原始表的原始表名
3刪掉原始表
總結(jié)一下就是,當(dāng)時(shí)刪除大表的一部分?jǐn)?shù)據(jù)時(shí)可以使用 見新表,拷貝數(shù)據(jù),刪除舊表,重命名的方法。
總結(jié)
以上是生活随笔為你收集整理的mysql快速删除大表数据部分数据_mysql删除大表的部分数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 翻转切换view,And
- 下一篇: linux cmake编译源码,linu