Information about table definitions is stored in the InnoDB data dictionary. If you move data files around, dictionary data can become inconsistent.
If a data dictionary corruption or consistency issue prevents you
Section 15.20.2, “Forcing InnoDB Recovery” for information about
[ERROR] InnoDB: Operating system error number 2 in a file operation. [ERROR] InnoDB: The error means the system cannot find the path specified. [ERROR] InnoDB: Cannot open datafile for read-only: './test/t1.ibd' OS error: 71 [Warning] InnoDB: Ignoring tablespace `test/t1` because it could not be opened.
To address the these messages, issue
TABLE statement to remove data about the missing table
from the data dictionary.
This procedure describes how to restore orphan
.ibd files to another MySQL instance. You
might use this procedure if the system tablespace is lost or
unrecoverable and you want to restore
file backups on a new MySQL instance.
The procedure is not supported for
The procedure assumes that you only have
.ibd file backups, you are recovering to
the same version of MySQL that initially created the orphan
.idb files, and that
.idb file backups are clean. See
Section 22.214.171.124, “Moving or Copying InnoDB Tables” for information about
creating clean backups.
Tablespace copying limitations outlined in Section 15.7.6, “Copying File-Per-Table Tablespaces to Another Instance” are applicable to this procedure.
On the new MySQL instance, recreate the table in a database of the same name.
mysql> CREATE DATABASE sakila; mysql> USE sakila; mysql> CREATE TABLE actor ( actor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (actor_id), KEY idx_actor_last_name (last_name) )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Discard the tablespace of the newly created table.
mysql> ALTER TABLE sakila.actor DISCARD TABLESPACE;
Copy the orphan
.idbfile from your backup directory to the new database directory.
shell> cp /backup_directory/actor.ibd path/to/mysql-5.7/data/sakila/
Ensure that the
.ibdfile has the necessary file permissions.
Import the orphan
.ibdfile. A warning is issued indicating that
InnoDBwill attempt to import the file without schema verification.
mysql> ALTER TABLE sakila.actor IMPORT TABLESPACE; SHOW WARNINGS; Query OK, 0 rows affected, 1 warning (0.15 sec) Warning | 1810 | InnoDB: IO Read error: (2, No such file or directory) Error opening './sakila/actor.cfg', will attempt to import without schema verification
Query the table to verify that the
.ibdfile was successfully restored.
mysql> SELECT COUNT(*) FROM sakila.actor; +----------+ | count(*) | +----------+ | 200 | +----------+