工作中遇到服务器出现故障,Mysql程序出现故障无法启动,庆幸data中的数据还在。本文介绍如何通过data中的数据文件恢复Mysql的数据
1、重新安装Mysql,建议5.7+的版本,恢复起来更方便
2、在新的数据库中创建同样的数据库及对应的表(相信这个在测试库会有同样的表,导出一份脚本就行了,如果没有就麻烦了)
3、利用navicat工具连接新库,执行脚本删除新库中的ibd文件
# 分离表空间文件
alter table biz_medal_item discard tablespace;
alter table biz_medal_wall discard tablespace;
alter table biz_run_data discard tablespace;
alter table biz_sport_index discard tablespace;
alter table biz_sport_input discard tablespace;
alter table biz_step_detail discard tablespace;
alter table biz_user_configuration discard tablespace;
执行完这个命令就会发现新库中的ibd文件都没了
4、然后将旧库中ibd文件拷贝到新库的对应目录下执行导入表空间命令
# 分离表空间文件
alter table biz_medal_item import tablespace;
alter table biz_medal_wall import tablespace;
alter table biz_run_data import tablespace;
alter table biz_sport_index import tablespace;
alter table biz_sport_input import tablespace;
alter table biz_step_detail import tablespace;
alter table biz_user_configuration import tablespace;
如果执行过程中出现row_format不正确的报错信息根据实际情况执行
alter table report_active row_format=DYNAMIC;
alter table report_active row_format=COMPACT;
然后重新执行上面的命令
至此基本就能完成数据库的恢复工作了
注意:此文档是针对Mysql5.7+的恢复方法,本人用的就是5.7。