A table with a table-specific tablespace (stored in an
.ibd file) can be restored individually without
taking down the MySQL server. This technique is applicable if you
delete or update the table data by mistake, without actually
losing the table itself through a
TRUNCATE TABLE, or
DROP DATABASE statement.
If you have a clean backup of an
.ibd file, you
can restore it to the MySQL installation from which it originated
For MySQL 5.5 and earlier, the table must already exist and not have been dropped or truncated since taking the backup. When an InnoDB table is truncated, or dropped and recreated, it gets a new table ID. Any ID mismatch between the table in the database and the backed-up table can prevent it from being restored. The requirement for matching table IDs is also the reason why you must restore to the same MySQL server from which the backup data came, not another server with a similar set of databases and tables. This restriction does not apply to MySQL 5.6 and later, as long as the restoration is made from one Generally Available (GA) version to another in the same series of MySQL servers.
Prevent write operations for the table to be restored. This prevents users from modifying the table while the restore is in progress.
Caution: This deletes the current
Copy the backup
.ibdfile back to the appropriate database directory.
Release the write lock to complete the restore procedure:
In this context, a clean
.ibd file backup means:
There are no uncommitted modifications by transactions in the
There are no unmerged insert buffer entries in the
Purge has removed all delete-marked index records from the
mysqld has flushed all modified pages of the
.ibdfile from the buffer pool to the file.
You can make such a clean backup
.ibd file with
the following method:
Stop all activity from the mysqld server and commit all transactions.
SHOW INNODB STATUSshows that there are no active transactions in the database, and the main thread status of
Waiting for server activity. Then you can make a copy of the
Another method for making a clean copy of an
.ibd file is to use
Use mysqlbackup with the
--only-innodb-with-frmoption to back up the
mysqlbackup ... apply-logto create a consistent version of the backup database.
Start a second (dummy) mysqld server on the backup and let it clean up the
.ibdfiles in the backup. Wait for the cleanup to end.
Shut down the dummy mysqld server.
Take a clean
.ibdfile from the backup.