天天看點

c mysql 删除資料庫檔案大小_mysql之delete删除記錄後資料庫大小不變

當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來回收空間