一、安装mysqlfrm工具
下载路径:https://downloads.mysql.com/archives/utilities/
二、操作过程
1. 新建临时数据库 temp
2. 将需要还原的表文件拷贝到 "d:/temp" 文件夹中
3. 执行下面命令,生成建表语句,语句中会自动将文件夹名作为数据库名
mysqlfrm --server=root:密码@localhost:3306 "d:\temp" > temp_frm.sql --diagnostic
4. 执行 temp_frm.sql(把文件中警告去掉)
5. 执行下面命令,生成丢弃表空间语句
mysql -u root -p -h localhost -P 3306 -e "select concat('alter table temp.',table_name,' discard tablespace;') as 'select 1;' from information_schema.tables where table_schema='temp';" > temp_discard.sql
6. 执行 temp_discard.sql
7. 拷贝原数据库表的.ibd文件至新数据库相应目录
8. 执行下面命令,生成导入表空间语句
mysql -u root -p -h localhost -P 3306 -e "select concat('alter table temp.',table_name,' import tablespace;')as 'select 1;' from information_schema.tables where table_schema='temp';" > temp_import.sql
9. 执行 temp_import.sql,数据恢复完成
10. 若数据恢复失败,请检查数据库版本是否一致。