I have a MySQL development server that uses InnoDB tables in some of the databases. It was originally setup with the defaults so all data went into the system tablespace (e.g the main ibdata1
file). Along the way, I enabled innodb_file_per_table so new database tables get into their own files.
I now want to reclaim disk space from dropping some development databases. I know I have to mysqldump and re-import those databases that are in the system tablespace. What is the best way to determine which ones to focus on?
I don't see anything obvious in the information_schema
database. I could manually poke around the server with an SSH shell, but I was looking for a more automated or elegant way to do that.
In some older databases, I only see .frm
files in the database directory, in newer ones I see .frm
and .ibd
files. That seems to be the key to know where the data is …
Sanity Check: Is it even possible to mysqldump half the databases to reclaim space, or do you really have to do every database? There are 54 databases inside this server that use InnoDB tables.
Note: Using MySQL v5.1 on UNIX.
Best Answer
Unfortunately, Yes you have to do every database. I have a step-by-step process I wrote up back on Oct 29, 2010 in StackOverflow as well as thorough explanation why there is nothing else you can do.
You also asked
You cannot reclaim half. It is an all-or-nothing decision. It is good to keep in mind what lives in ibdata1 when innodb_file_per_table is disabled :
Pictorial Representation of ibdata1
Still, if you want to know which InnoDB tables are in ibdata1 and which are in their own tablespace file (
.ibd
), here is what you do:STEP 01 : Run this query in the MySQL client
STEP 02 : Collect the number of
.ibd
files in the OSSTEP 03 : Subtract those values in the OS
Here is the shell script to compute these things
If you have partitioned tables, then do this:
Here is what you get:
IB_TOT
: Number of InnoDB Tables in the MySQL InstanceIB_IBD
: Number of InnoDB Tables Residing Outsideibdata1
as.ibd
FilesIB_SYS
: Number of InnoDB Tables Residing Insideibdata1