Mysql – Handling Recovery of Disk Space in MySQL and MongoDB

disk-spacemaintenanceMySQL

So I have worked with MySQL all my life (not as a DBAdmin, but a programmer), and I have some limited knowledge about maintaining MySQL databases.

Recently a portion of our database has been moved to MongoDB and we have outsourced MongoDB administration to another company. They informed us that with MongoDB, when data is deleted disk space is NOT recovered and that specific clean up tasks need to be done for this which require downtime.

What I wanted to ask here is that: They also said the same is applicable to MySQL (where if we delete data, disk space is not recovered and we need to run clean up scripts for that purpose). I was never aware about this regarding MySQL.

Can anyone tell me briefly how this works for MySQL or point me to any good resources that I can understand?

Best Answer

InnoDB

I have mentioned how to shrink InnoDB tables and the System Tablespace (ibdata1) in the past

MyISAM

You could simply run for mydb.mytable

OPTIMIZE TABLE mydb.mytable;

which will shrunk a MyISAM table and recalculate the index statistics. To shrink all MyISAM tables, see my Jul 24, 2012 answer to MySQL: reducing ibdata file size for MyISAM tables

GIVE IT A TRY !!!