1、问题描述
公司的技术支持人员跟我反映说:使用Navicat导出mysql数据库,导到一半时报错,出现MySQL10061错误,很显然是mysql进程挂了。查看系统服务也证实了这点。
为什么导出数据库就导致mysql进程挂掉?我百思不得其解,因为我在本地经常导数据库,从未遇到类似的问题。
2、问题分析
既然mysql进程挂了,那应该有日志记录吧。
mysql错误日志路径:安装路径\mysql\Data\LAPTOP-2LNJRPK1.err
查看mysql错误日志:
2021-10-17T12:36:00.006701Z 4 [ERROR] InnoDB: Table cms/cms_master_member contains 2 indexes inside InnoDB, which is different from the number of indexes 3 defined in MySQL
2021-10-17T12:36:00.007399Z 4 [ERROR] InnoDB could not find key no 2 with name master_member_status_index from dict cache for table cms/cms_master_member
2021-10-17T12:36:00.007915Z 4 [ERROR] Table cms/cms_master_member contains fewer indexes inside InnoDB than are defined in the MySQL .frm file. Have you mixed up .frm files from different installations? Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
3、问题原因
[ERROR] InnoDB could not find key no 2 with name master_member_status_index from dict cache for table cms/cms_master_member
从错误日志可知:是因为索引 master_member_status_index 在mysql的缓存中找不到,所以mysql报错了,导致mysql进程挂掉。
那么为什么索引会在缓存中找不到呢?
后经与技术支持人员沟通,原来他们经常使用mysql的.frm和.ibd来备份恢复数据,不可避免再操作过程中出现了索引不一致的问题。
查看mysql错误日志里的修复指引连接也证实这一点:https://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
备注:
.frm文件:保存了每个表的元数据,包括表结构的定义等;
.ibd文件:InnoDB引擎开启了独立表空间(my.ini中配置innodb_file_per_table = 1)产生的存放该表的数据和索引的文件。
4、问题修复
方案1:如果可以的话, 删掉问题索引
方案2:在 \mysql\my.ini配置文件中添加配置:innodb_force_recovery = 1
强制修复innodb数据
我这边选择的是方案1,因为查看了下问题索引,觉得没什么用,可以删掉。
至此,问题解决,成功导出数据库 。