環境: CentOS 7.x
、MySQL 5.7
実際、この種の問題にはさまざまな理由がありますが、問題が何であっても、最終的な理由は通常、問題によってredo log
引き起こされます。
対応するファイルは ib_logfile0、ib_logfile1で始まるため、なぜこの問題が
redo log
発生する? 次の質問はすべてに関連しています。MySQL エンジンの具体的な原理についてはここでは掘り下げず、後で詳しく説明します。redo log
ib_logfile
ib_logfile
以下は、InnoDB
エンジンの。
テスト環境は頻繁に破棄されるため、次のシナリオではテスト環境でより問題になりますが、実稼働環境では一般的な操作が非常に慎重であり、シャットダウンも頻繁ではないため、実稼働環境では破棄されていません。
シナリオ 1: サーバーが突然再起動し、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.
# InnoDB:忽略重做日志,因为检查点 9156630714 和结束 9156630528 之间缺少 MLOG_CHECKPOINT。
シナリオ 2: サーバーを正常にシャットダウンできず、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!
# 看问题是因为 ib_logfile0 实际的大小 5242880 与 cnf 文件中指定的 104857600 不一致;
# 大概率是丢数据造成的。
解決
エラーが表示されるのは問題redo log
です。ログ ファイルがどこに保存されているかわからない場合は、グローバルに検索できます。
# 从根目录开始搜索 ib_logfile 开头的文件
find ./ -name ib_logfile*
./var/lib/mysql/ib_logfile1
./var/lib/mysql/ib_logfile0
# 在 /var/lib/mysql 目录下;将文件改个名字备份一下
cd /var/lib/mysql
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
# 启动 mysql
systemctl start mysqld
[注意]ib_logfile
ファイルを、データが失われる可能性がありますので、操作前にバックアップを作成し、問題が発生した場合に復元することをお勧めします。
個人ブログ: Roc のブログ