Thesql 5.5 corrupt – missing temporary table

corruptioninnodbMySQLmysql-5.5temporary-tables

One of our mysql instances crashed and failed to start:

120422 10:04:13  InnoDB: Error: trying to open a table, but could not
InnoDB: open the tablespace file './databasename/#sql-29f6_45.ibd'!
InnoDB: Have you moved InnoDB .ibd files around without using the
InnoDB: commands DISCARD TABLESPACE and IMPORT TABLESPACE?
InnoDB: It is also possible that this is a temporary table #sql...,
InnoDB: and MySQL removed the .ibd file for this.
InnoDB: Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting-datadict.html
InnoDB: for how to resolve the issue.

I've failed to understand what should I do in order to remove this temporary table from the TABLESPACE.

How should I proceed?

Best Answer

There are those rare times when an InnoDB table gets stuck in the ibdata1 deeply that you must try forecing mysql to start up in spite of it.

Try using innodb_force_recovery in /etc/my.cnf (Option values 1-6)

[mysqld]
innodb_force_recovery = 1

then restart mysql.

This should at least allow a mysqldump

mysqldump -u... -p... --routines --triggers --all-databases > /root/MySQLData.sql

Once you have mysqldumped all data, remove the innodb_force_recovery

Then, perform a complete cleanup of InnoDB as follows

service mysql stop
mv /var/lib/mysql /var/lib/mysql_old
mkdir /var/lib/mysql
mkdir /var/lib/mysql/mysql
cp /var/lib/mysql_old/mysql/* /var/lib/mysql/mysql/.
chown -R mysql:mysql /var/lib/mysql
service mysql start
mysql -u... -p... < /root/MySQLData.sql

After service mysql start, new InnoDB files (ibdata1, ib_logfile0, ib_logfile1) are created

Give it a Try !!!

Related Question