在测试环境中模拟了ibd文件损坏的一个情况,实例启动的状态下直接清空了表的ibd文件。这个时候实例是正常访问的,重启后再次访问这个表导致实例关闭。再次启动,错误日志中提示:
2017-10-16 15:16:39 11370 [ERROR] InnoDB: Tried to read 16384 bytes at offset 0. Was only able to read 0.
2017-10-16 15:16:39 7f17e7a69740 InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
2017-10-16 15:16:39 11370 [ERROR] InnoDB: File (unknown): ‘read’ returned OS error 71. Cannot continue operation

在目录中删除这个表的ibd和frm文件,实例启动成功,但是再次创建同名表的时候,提示表已经存在。
mysql> create table p1(id int,name varchar(20));
ERROR 1050 (42S01): Table ‘test.p1’ already exists
mysql> drop table p1;
ERROR 1051 (42S02): Unknown table ‘test.p1’
mysql> drop table p1;
ERROR 1051 (42S02): Unknown table ‘test.p1’
mysql> create table p1(id int,name varchar(20));
ERROR 1813 (HY000): Tablespace for table ‘test.p1’ exists. Please DISCARD the tablespace before IMPORT.

需要将frm文件拷贝回来,在drop表,然后在备份中恢复表