mysql之delete刪除記錄後資料庫大小不變_Mysql

來源:互聯網
上載者:User

當DELETE後面跟條件的時候,則就會出現這個問題

delete from table_name where 條件

刪除資料後,資料表佔用的空間大小不會變。

不跟條件直接delete的時候。

delete from table_name

清除了資料,同時資料表的空間也會變為0

如果已經刪除了表資料的很大一部分,或者有很多變化和變長表行(VARCHAR表,VARBINARY、BLOB或文本列)進行了更改,因為刪除操作後在資料檔案中留下片段所致。DELETE只是將資料標識位刪除,並沒有整理資料檔案,當插入新資料後,會再次使用這些被置為刪除標識的記錄空間,可以使用OPTIMIZE TABLE來回收未使用的空間,並整理資料檔案的片段。

OPTIMIZE TABLE只對MyISAM, BDB和InnoDB表起作用。

OPTIMIZE TABLE 表名;

針對myisam引擎,使用optimize table 還有如下功能:

If the table has deleted or split rows, repair the table. [修複表]If the index pages are not sorted, sort them. [索引未排序,會排序]If the table's statistics are not up to date (and the repair could not be accomplished by sorting the index), update them.[若表的統計資訊不是最新的,更新它]

對myiam資料表進行大量刪除後,發現空間沒有回收,要通過optimize table來回收空間

以上所述是小編給大家介紹的mysql之delete刪除記錄後資料庫大小不變的相關知識,希望對大家有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.