目录
- 场景一:服务器突然重启,未正常关闭 MySQL
- 场景二:服务器正常关机关不掉,然后强制 kill 掉 MySQL 进程
- 解决方案
环境:CentOS 7.x
、MySQL 5.7
其实造成这种问题的原因有很多种,但是不管是什么问题,最终的原因一般是 redo log
造成的问题。
为什么说是 redo log
造成的呢,因为 redo log
对应的文件就是两个 ib_logfile
开头的文件:ib_logfile0、ib_logfile1;下面的问题都是和 ib_logfile
有关。
MySQL 引擎的具体原理,这里暂不深究了,等后续再详细整理。
下面是实际遇到的造成 InnoDB
引擎不能启动的场景:
由于测试环境经常折腾,对于下面的场景而言,更多的是测试环境出现的问题;生产的话一般操作很谨慎,也不会频繁关机,所以还没有在生产上折腾过。
场景一:服务器突然重启,未正常关闭 MySQL
在测试环境中,服务器直接强制断电(Power Off
),并没有手动的关闭 MySQL
,再次启动的时候就会发生这样的问题。
2023-03-21T05:30:22.710453Z 0 [ERROR] InnoDB: Ignoring the redo log due to missing MLOG_CHECKPOINT
between the checkpoint 9156630714 and the end 9156630528.
2023-03-21T05:30:22.710511Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2023-03-21T05:30:23.311477Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2023-03-21T05:30:23.311521Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2023-03-21T05:30:23.311534Z 0 [ERROR] Failed to initialize plugins.
2023-03-21T05:30:23.311542Z 0 [ERROR] Aborting
问题的主要原因:
InnoDB: Ignoring the redo log due to missing MLOG_CHECKPOINT between the checkpoint 9156630714 and the end 9156630528.
场景二:服务器正常关机关不掉,然后强制 kill 掉 MySQL 进程
就说巧不巧吧,再测试环境中,上面是直接断电有问题,然而本想正常关机,结果也不行;MySQL
一直卡在那里,尝试 kill
还是无法停止,无奈只好 kill -9
(强制退出)掉 MySQL
。
服务器启动后,开始启动 MySQL
,然后报错如下:
2023-03-21T05:30:22.710511Z InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
2023-03-21T05:30:22.710511Z InnoDB: than specified in the .cnf file 0 104857600 bytes!
2023-03-21T05:30:22.710511Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2023-03-21T05:30:23.311477Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2023-03-21T05:30:23.311521Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2023-03-21T05:30:23.311534Z 0 [ERROR] Failed to initialize plugins.
2023-03-21T05:30:23.311542Z 0 [ERROR] Aborting
主要原因:
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 104857600 bytes!
解决方案
看错误是 redo log
有问题;如果不知道这个日志文件存放在哪里,可以全局搜索一下:
find ./ -name ib_logfile*
./var/lib/mysql/ib_logfile1
./var/lib/mysql/ib_logfile0
cd /var/lib/mysql
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
systemctl start mysqld
【注】直接删除 ib_logfile
文件,可能会造成部分数据丢失,建议操作之前先备份一下;万一出问题还能进行一下还原。
个人博客:Roc’s Blog
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)