暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

【生产篇】_mysqlbackup备份异常遇到的ib_logfile问题

原创 Ethan_Yang 2019-10-28
2661

【引言】
因项目组需求,使用mysqlbackup备份服务器A下的一镜像文件,然后恢复到服务器B的mysql新进程上,启动mysql的时候报/ib_logfile0 错误。

备份命令:
#/usr/local/bin/mysqlbackup --defaults-file=/etc/my3307.cnf --datadir=/mysqldata/mysql3307/ --backup-image=/mysqldata/backup/phy_vehi_full_10-15-2019.mbi --uncompress --force --backup-dir=/mysqldata/tmp1/backup copy-back-and-apply-log

恢复命令:
#/usr/local/bin/mysqlbackup --defaults-file=/etc/my3307.cnf --datadir=/mysqldata/mysql3307/ --backup-image=phy_vehi_full_10-15-2019.mbi --uncompress --force --backup-dir=/mysqldata/tmp1/backup copy-back-and-apply-log

报错信息:
2019-10-16T09:46:49.586347Z 0 [ERROR] InnoDB: ./ib_logfile0 can’t be opened in read-write mode.
2019-10-16T09:46:49.586379Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-10-16T09:46:50.187018Z 0 [ERROR] Plugin ‘InnoDB’ init function returned error.
2019-10-16T09:46:50.187074Z 0 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.
2019-10-16T09:46:50.187109Z 0 [ERROR] Failed to initialize builtin plugins.
2019-10-16T09:46:50.187119Z 0 [ERROR] Aborting

2019-10-16T09:46:50.187143Z 0 [Note] Binlog end
2019-10-16T09:46:50.187238Z 0 [Note] Shutting down plugin ‘MyISAM’
2019-10-16T09:46:50.187279Z 0 [Note] Shutting down plugin ‘CSV’
2019-10-16T09:46:50.188220Z 0 [Note] /usr/local/bin/mysqld: Shutdown complete

因时间紧急,网上查找了下解决方法,步骤如下:

  1. 检查ib_logfile0  文件权限是否正确;
  2. 如果在使用chown mysql:mysql  chmod 766 依然无效时;考虑删除ib_logfile0,1 日志,因为是刚刚prepare后生成的文件,日志文件中不包含业务数据;
  3. 再次使用mysqld_safe 启动mysql时会重新生成ib_logfile*

解决方法:
1、关闭mysql数据库
2、进入mysql的/mysqldata/mysql3307目录,删除以下2个文件:ib_logfile0和 ib_logfile1
3、重新启动mysql,成功。

ib_logfile是个嘛?
MySQL的innodb中事务日志ib_logfile,或称redo日志,在mysql中默认以ib_logfile0,ib_logfile1名称存在,可以手工修改参数,调节开启几组日志来服务于当前mysql数据库,mysql采用顺序,循环写方式,每开启一个事务时,会把一些相关信息记录事务日志中(记录对数据文件数据修改的物理位置或叫做偏移量);

ib_logfile的作用
在系统崩溃重启时,作事务重做;在系统正常时,每次checkpoint时间点,会将之前写入事务应用到数据文件中。

【疑问】
为什么删除ib_logfile0和 ib_logfile1后,就可以重启mysql,不是很明白,后续接着研究。也欢迎明白原因的朋友留言交流。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论