The following procedure can be used to recover InnoDB database tables from a backup of a MySQL server that had the “
innodb_file_per_table” setting but all the metadata (in the “
ibdata*” files) was lost – for example due to a server crash.
The process involves two steps:
- Recover the table structure from the
- Recover the data from the
.ibdfiles (InnoDB tablespace)
There is a lot of copying the backed up files over and over to the MySQL datadir, so its useful to have the backup available on the database server machine. In my setup the backup for the databases was copied to the directory “backup” under the database’s datadir, so – for example – for the table
somedb.sometable there exist files
Additionally the process for recovering the table structures creates a lot of superfluous metadata in the InnoDB data files, so after the first stage I’m going to destroy the InnoDB data files and let the InnoDB engine re-generate them – as a result any existing InnoDB tables will be destroyed. This is important so I’ll iterate: using the procedure detailed here will destroy any existing and working InnoDB databases! So this procedure is useful to recover a destroyed database server to a new server or as a temporary measure on a temporary server to be able to dump the data to SQL files that will later be loaded into an existing server.
There likely a way to do this which is less heavy handed – for example, check out this article from Percona’s MySQL blog, but for my purpose this is enough.