InnoDB stores all tables in one big file ibdata1
.
After dropping a big table, the file is keeping its size no matter how big the table was.
How can I shrink that file without having to dump and re-import the whole database (which has several Hundred GB in total)?
I think the reason is because you are still able to rollback the dropping. In my case I don't need to.
Best Answer
This is one of the most controversial topics I have ever dealt with over the years as a MySQL DBA and in the DBA StackExchange.
To put it mildly, there is simply no other way to shrink ibdata1. With innodb_file_per_table disabled, every time you run
OPTIMIZE TABLE
on an InnoDB table, ibdata1 grows rapidly. Data that are dropped usingDROP TABLE
andDROP DATABASE
cannot be rolled back because they are DDL, not DML. I believe Oracle and MSSQL can rollback DDL. MySQL cannot do that.There are several classes of information that reside in ibdata1
Using
innodb_file_per_table=1
will allow you to create new tables with table data and table indexes being created outside ibdata1. You could extract any tables still inside ibdata1 usingALTER TABLE ... ENGINE=InnoDB;
orOPTIMIZE TABLE
but that will leave that big gaping unused space in ibdata1.Notwithstanding, you must clean up the InnoDB infrastructure. I already wrote StackExchange posts on how and why to do this:
May 21, 2012
: How large will a MySQL database be relative to the dump file?Apr 01, 2012
: Is innodb_file_per_table advisable?Mar 25, 2012
: Why does InnoDB store all databases in one file?Feb 04, 2011
: MySQL InnoDB - innodb_file_per_table cons?Oct 29, 2010
: Howto: Clean a mysql InnoDB storage engine?Good News
You only have to dump the data, reload one more time and never revisit this issue again. Running
OPTIMIZE TABLE
afterwards will indeed shrink the.ibd
tablespace file for any InnoDB table.