I have the complete answer for this one.
Once innodb_file_per_table is put in place, and new InnoDB tables can be shrunk using ALTER TABLE <innodb-table-name> ENGINE=InnoDB';
This will shrink new .ibd
files GUARANTEED.
If you run ALTER TABLE <innodb-table-name> ENGINE=InnoDB';
on an InnoDB table created before you used innodb_file_per_table, it will yank the data and indexes for that table out of the ibdata1 file and store it in a .ibd
file, This will leave a permanent pigeon whole in the ibdata1 that can never be reused.
The ibdata1
file normally houses four types of information
Here is the guaranteed way to shrink the ibdata1 file pretty much forever...
STEP 01) MySQLDump all databases into a SQL text file (call it SQLData.sql)
STEP 02) Drop all databases (except mysql, information_schema and performance_schema schemas)
STEP 03) Shutdown mysql
STEP 04) Add the following lines to /etc/my.cnf
[mysqld]
innodb_file_per_table
innodb_flush_method=O_DIRECT
innodb_log_file_size=1G
innodb_buffer_pool_size=4G
innodb_data_file_path=ibdata1:10M:autoextend
Sidenote: Whatever your set for innodb_buffer_pool_size, make sure innodb_log_file_size is 25% of innodb_buffer_pool_size.
- STEP 05) Delete ibdata1, ib_logfile0 and ib_logfile1 (see update below before deleting!)
At this point, there should only be the mysql schema in /var/lib/mysql
This will recreate ibdata1 at 10MB (do not configure the option) , ib_logfile0 and ib_logfile1 at 1G each
- STEP 07) Reload SQLData.sql into mysql
ibdata1
will grow but only contain table metadata and intermittent MVCC data.
Each InnoDB table will exist outside of ibdata1
Suppose you have an InnoDB table named mydb.mytable. If you go into /var/lib/mysql/mydb
, you will see two files representing the table
mytable.frm
(Storage Engine Header)
mytable.ibd
(Home of Table Data and Table Indexes for mydb.mytable
)
ibdata1
will never contain InnoDB data and Indexes anymore.
With the innodb_file_per_table option in /etc/my.cnf
, you can run OPTIMIZE TABLE mydb.mytable
OR ALTER TABLE mydb.mytable ENGINE=InnoDB;
and the file /var/lib/mysql/mydb/mytable.ibd
will actually shrink.
I have done this numerous times in my career as a MySQL DBA without so much as a single problem thereafter. In fact, the first time I did this, I collapsed a 50GB ibdata1 file into 50MB.
Give it a try. If you have further questions on this, email me. Trust me. This will work in the short term and over the long haul.
UPDATE 2013-07-02 15:08 EDT
There is a caveat I have in this regard that I updated in other posts of mine but I missed this: I am updating my answer a little more with innodb_fast_shutdown because I used to restart mysql and stop mysql to do this. Now, this one-step is vital because every transaction uncommitted may have other moving parts within and outside of the InnoDB Transaction Logs (See InnoDB Infrastructure).
Please note that setting innodb_fast_shutdown to 2 would clean the logs out as well but more moving parts still exist and gets picked on Crash Recovery during mysqld's startup. Setting of 0 is best.
You need to do a mysqldump of everything !!!
With regard to the error message, you have what I call a pidgeon hole. It is essentially a table's metadata that got corrupted in ibdata1. There is no way to erase it. You cannot drop the table the metadata is looking for because the corresponding data outside ibdata1 cannot be referenced via its inode. Sometimes, even mysqldumps won't work when it hits the table entry via the .frm.
From another perspective, the metadata contained in ibdata1 is Lunix-ish and inode centric, which are concepts foreign to FAT-based Windows. I would not trust InnoDB metadata built this way. Doing a mysqldump gives you logcial data representation via SQL that is both OS and hardware agnostic.
If the datadump is too big, you need to do parallel dumps of the databases or tables and load those mysqldumps into MySQL Windows.
If you are unsure or wary of scripting this, get MAATKIT and use mk-parallel-dump (deprecated tool but good for adhoc dumps) to spit out the data as CSV files. Then, use 'mysqldump --no-data --routines --triggers' and generate table structures file. Run the table structures file in MySQL Windows. Finally, load the CSV into MySQL Windows using LOAD DATA INFILE.
Best Answer
No, you are going to have to do a dump and restore. Even after doing the
alter table engine
trick, some data will remain in the ibdata1 file.I have run into this issue myself, and dumping all the tables and then re-importing them without shutting down mysql doesnt work. All innodb tables must be gone before you can remove the ibdata1 file.