国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

mysql刪除超大表中的部分數據

2024-07-24 12:36:46
字體:
來源:轉載
供稿:網友

mysql中刪除一般表數據我們會使用delete 或者truncate來清空表數據,但是如果碰到超大表時你會發現此方法有點困難了,下面我以一個mysql刪除超大表中的部分數據為示例給各位同學介紹介紹.

mysql普通刪除表

delete 語句的定義:經常和數據庫打交道的孩子們,刪除數據的時候用的大多都是 delete 語句,現在讓我們來看一下 delete語句的定義.

  1. DELETE [LOW_PRIORITY] [QUICK] [IGNOREFROM tbl_name 
  2.  
  3. [WHERE where_definition] 
  4.  
  5. [ORDER BY ...] 
  6.  
  7. [LIMIT row_count] 

例,代碼如下:

  1. delete from friends where user_name = ‘simaopig’; 
  2.  
  3. truncate 語句 TRUNCATE [TABLE] tbl_name 

這里簡單的給出個示例,我想刪除 friends 表中所有的記錄,Vevb.com,可以使用如下語句:

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 m.survivalescaperooms.com 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,刪掉原始表

總結一下就是,當時刪除大表的一部分數據時可以使用 見新表,拷貝數據,刪除舊表,重命名的方法.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吉木乃县| 海安县| 红河县| 长沙县| 社会| 卢氏县| 和田县| 塔河县| 永善县| 石柱| 余干县| 平凉市| 三原县| 塘沽区| 武冈市| 新龙县| 兴山县| 岳池县| 望都县| 周口市| 厦门市| 和平区| 泉州市| 望都县| 东莞市| 云南省| 那坡县| 安远县| 德格县| 华宁县| 大安市| 嘉义市| 紫云| 察哈| 邵东县| 佳木斯市| 浪卡子县| 汪清县| 湘西| 射洪县| 射阳县|