LoginSignup
18
17

More than 5 years have passed since last update.

MySQLでInnoDB破損したときの復旧方法

Posted at

何かの拍子にInnoDBが破損してMySQL起動できなくなったときの対処方法です。

160804 11:47:28  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 110757537189
160804 11:47:29 [ERROR] mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.

To report this bug, see http://kb.askmonty.org/en/reporting-bugs

We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.

修復手順

強制起動

  • MySQLが起動している場合はサービスを停止する
  • datadirに使っている/var/lib/mysqlを一応バックアップ
  • /etc/my.cnfの[mysqld]innodb_force_recoveryを追記して、InnoDBを強制リカバリモードで起動
    • 警告:innodb_force_recovery は、緊急時にのみ0より大きい値に設定してください。また、値を4以上にするとデータファイルが恒久的に破損する可能性があります。詳しくは公式マニュアルを参照してください
/etc/my.cnf
[mysqld]
innodb_force_recovery = 3
  • innodb_force_recoveryのみで起動しない場合innodb_purge_threadsを追加
/etc/my.cnf
[mysqld]
innodb_purge_threads=0

ダンプ・リストア

  • 全データベースをダンプ
# mysqldump -u root -p -x --all-databases > alldatabase.dump
  • MySQLをシャットダウン
    • mysqldがシャットダウンできないときは強制kill
# ps xa | grep mysql
# kill -9 safe_mysqldのpid
# kill -9 mysqldのpid
  • mysqlフォルダを除くすべてのMySQLデータストレージファイルを削除、もしくはどこかに退避
# rm -rf `ls -d /var/lib/mysql/* | grep -v "/var/lib/mysql/mysql"`
  • /etc/my.cnfのinnodb_force_recoveryを削除
  • MySQLを再起動
  • ダンプファイルをリストアする
# mysql -u root -p < alldatabase.dump

教訓

mysqldumpとかで定期的なバックアップを必ず取っておく。

参考

18
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
17