mysql之delete刪除記錄后數(shù)據(jù)庫大小不變_MySQL

當(dāng)delete后面跟條件的時(shí)候,則就會(huì)出現(xiàn)這個(gè)問題

delete from table_name where 條件

刪除數(shù)據(jù)后,數(shù)據(jù)表占用的空間大小不會(huì)變。

不跟條件直接delete的時(shí)候。

 delete from table_name

清除了數(shù)據(jù),同時(shí)數(shù)據(jù)表的空間也會(huì)變?yōu)?

如果已經(jīng)刪除了表數(shù)據(jù)的很大一部分,或者有很多變化和變長(zhǎng)表行(VARCHAR表,VARBINARY、BLOB或文本列)進(jìn)行了更改,因?yàn)閯h除操作后在數(shù)據(jù)文件中留下碎片所致。DELETE只是將數(shù)據(jù)標(biāo)識(shí)位刪除,并沒有整理數(shù)據(jù)文件,當(dāng)插入新數(shù)據(jù)后,會(huì)再次使用這些被置為刪除標(biāo)識(shí)的記錄空間,可以使用OPTIMIZE TABLE來回收未使用的空間,并整理數(shù)據(jù)文件的碎片。

OPTIMIZE TABLE只對(duì)MyISAM, BDB和InnoDB表起作用。

OPTIMIZE TABLE 表名;

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

 If the table has deleted or split rows, repair the table. [修復(fù)表] If the index pages are not sorted, sort them. [索引未排序,會(huì)排序] If the table's statistics are not up to date (and the repair could not be accomplished by sorting the index), update them.[若表的統(tǒng)計(jì)信息不是最新的,更新它]

對(duì)myiam數(shù)據(jù)表進(jìn)行批量刪除后,發(fā)現(xiàn)空間沒有回收,要通過optimize table來回收空間

以上所述是小編給大家介紹的mysql之delete刪除記錄后數(shù)據(jù)庫大小不變的相關(guān)知識(shí),希望對(duì)大家有所幫助!

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊5 分享