国产探花免费观看_亚洲丰满少妇自慰呻吟_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 www.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,刪掉原始表

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵港市| 剑阁县| 池州市| 同心县| 澎湖县| 永仁县| 渑池县| 于田县| 陇川县| 蓬莱市| 当阳市| 亚东县| 兴化市| 新竹县| 台州市| 布尔津县| 怀集县| 叙永县| 车致| 独山县| 桃源县| 汉中市| 衡山县| 伊宁市| 商南县| 浦北县| 全州县| 德钦县| 个旧市| 金溪县| 尤溪县| 浮梁县| 石嘴山市| 常山县| 卫辉市| 沂水县| 应用必备| 隆化县| 江城| 吉隆县| 新安县|