程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql刪除大表的部分數據

mysql刪除大表的部分數據

編輯:MySQL綜合教程


mysql刪除大表的部分數據   好久沒寫博客。最近項目要上線。下班時間還得陪著老媽。實在沒時間更新。   今天有人提了一個問題,  www.2cto.com     一個表有1億6000萬的數據,有一個自增ID。最大值就是1億6000萬,需要刪除大於250萬以後的數據,有什麼辦法可以快速刪除? 當時看了一眼數據嚇尿了,這麼大的數據要刪除到什麼時候啊,最要命的鎖表腫麼辦   delete是不行了,加索引也別想。mysql上delete加low_priorty,quick,ignore估計也幫助不大   看到mysql文檔有一種解決方案:http://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文不好,簡單的翻譯下:   刪除達標上的多行數據時,innodb會超出lock table size的限制,最小化的減少鎖表的時間的方案是:   1選擇不需要刪除的數據,並把它們存在一張相同結構的空表裡   2重命名原始表,並給新表命名為原始表的原始表名   3刪掉原始表   總結一下就是,當時刪除大表的一部分數據時可以使用 見新表,拷貝數據,刪除舊表,重命名的方法。
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved