This article covers how to recover the orphan InnoDB database from the ibd file.
Orphan InnoDB database incident mostly happened when:
1 – user accidentally remove ibdata1 file. (mostly in /var/lib/mysql/ibdata1).
2 – ibdata file courrupted.
To Recover Orphaned InnoDB Tables:
1. Restart the MySQL service to recreate ibdata1, then take a backup of your database folder.
2. Login to MySQL.
3. Create a dummy database with the same name. Then, create a dummy table with the same name as the corrupted one (don’t mind the table structure for now).
4. Stop the MySQL service, copy the .frm file from the backup you took to replace the .frm file.
5. Start MySQL and have a look at the structure of your table - it should now be in place! However, don’t get too happy yet.
6. Issue a SHOW CREATE TABLE statement and copy its contents, then create the table with them.
7. Stop MySQL, copy the .ibd file from the backup directory to /var/lib/database_name and replace the existing .ibd file from the dummy table.
8. Now it’s time for Percona’s tools to shine - download and install the Percona Data Recovery Tool for InnoDB , then run the following (here -o represents the full location of your ibdata1 file, -f represents the full location of your .ibd file, -d represents the database name and -t represents your table name):
ibdconnect -o /var/lib/mysql/ibdata1 -f /var/lib/mysql/database_name/table_name.ibd -d database_name -t table_name
9. Now, run a checksum check against InnoDB - make sure you get no error messages (you might need to run this tool several times):
10. Finally, you should be good to go - simply start MySQL.