mysql普通刪除表
delete 語句的定義:
經常和數據庫打交道的孩子們,刪除數據的時候用的大多都是 delete 語句。現在讓我們來看一下 delete語句的定義。
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
[WHERE where_definition]
[ORDER BY ...]
[LIMIT row_count]
例
delete from friends where user_name = ‘simaopig’;
truncate 語句 TRUNCATE [TABLE] tbl_name
這裡簡單的給出個示例,我想刪除 friends 表中所有的記錄,111cn.net可以使用如下語句:
truncate table friends;
但在我在刪除超大表時發現 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 www.111cn.net 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刪掉原始表
總結一下就是,當時刪除大表的一部分數據時可以使用 見新表,拷貝數據,刪除舊表,重命名的方法。