ネットワーク/MySQL、InnoDBのリカバリができず起動できない http://www.ark-web.jp/sandbox/wiki/228.html
ネットワーク/MySQL、InnoDBのリカバリができず起動できない
- 先日サーバーがリソース不足で牛歩状態となり操作不能となったため、強制シャットダウンしました。
- そうしたらMySQLが起動しなくなってしまいました。
- ログをみると、次のようにでていました。
070901 18:35:43 mysqld started 070901 18:35:43 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... 070901 18:35:43 InnoDB: Starting log scan based on checkpoint at InnoDB: log sequence number 1 4073110871. InnoDB: Doing recovery: scanned up to log sequence number 1 4073111019 InnoDB: 1 transaction(s) which must be rolled back or cleaned up InnoDB: in total 1 row operations to undo InnoDB: Trx id counter is 0 140789504 070901 18:35:43 InnoDB: Starting an apply batch of log records to the database... InnoDB: Progress in percents: 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 InnoDB: Apply batch completed InnoDB: Starting rollback of uncommitted transactions InnoDB: Rolling back trx with id 0 140789009, 1 rows to undoInnoDB: Error: trying to access page number 532303 in space 0, InnoDB: space name ./ibdata1, InnoDB: which is outside the tablespace bounds. InnoDB: Byte offset 0, len 16384, i/o type 10 070901 18:35:43InnoDB: Assertion failure in thread 1128208 in file fil0fil.c line 3922 InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to http://bugs.mysql.com. InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: http://dev.mysql.com/doc/mysql/en/Forcing_recovery.html InnoDB: about forcing recovery. 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. 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. key_buffer_size=0 read_buffer_size=131072 max_used_connections=0 max_connections=100 threads_connected=0 It is possible that mysqld could use up to key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 217599 K bytes of memory Hope that's ok; if not, decrease some variables in the equation. thd=(nil) Attempting backtrace. You can use the following information to find out where mysqld died. If you see no messages after this, something went terribly wrong... Cannot determine thread, fp=0xbfee8088, backtrace may not be correct. Stack range sanity check OK, backtrace follows: 0x812b880 0xa44420 0x82931de 0x82931de 0x8285901 0x82b2f4d 0x82b2331 0x826a9c8 0x8281f9e 0x827a4f4 0x8274b09 0x821206e 0x8212798 0x8272f85 0x82a1126 0x81f97e2 0x81b119f 0x81a8925 0x812ccde 0x812d279 0xbcc724 0x80c7031 New value of fp=(nil) failed sanity check, terminating stack trace! Please read http://dev.mysql.com/doc/mysql/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved stack trace is much more helpful in diagnosing the problem, so please do resolve it The manual page at http://www.mysql.com/doc/en/Crashing.html contains information that should help you find out what is causing the crash. 070901 18:35:43 mysqld ended
- どうやら、未コミットなトランザクションなどのリカバリに失敗している、とかそういう感じでしょうか。
- エラーログにある、
MySQL AB :: MySQL 4.1 リファレンスマニュアル :: 7.5.7.1 強制的なリカバリ
http://dev.mysql.com/doc/refman/4.1/ja/forcing-recovery.html
の内容などを参考にして、my.cnfに、[mysqld] innodb_force_recovery=3
などを追加して起動はすることができました。 - でも、selectはできますが、drop tableなどは
InnoDB: !!! innodb_force_recovery is set to 3 !!!
といったエラーがエラーログにでて、実行できません。
マニュアルには、drop tableはできる、と書いてあるのに。 - 同様に、SELECT INTO OUTFILEはできますが、LOAD DATA INFILEも同じエラーがでて実行できませんでした。
- なので、次のような手順で対応しました。
- 今の、datadir /var/lib/mysqlを一応 /var/lib/mysql_backにバックアップ
- /etc/my.cnfに次を追記して、InnoDBを強制リカバリモードで起動
[mysqld] innodb_force_recovery = 3
- 全データベースをダンプ
mysqldump --default-character-set=latin1 databasename > databasename.sql ....
- mysqldがシャットダウンできないので、強制 kill
ps xa | grep mysql kill -9 safe_mysqldのpid kill -9 mysqldのpid
- /var/lib/msyql2 というディレクトリを作成
- mysql_install_dbを--datadirを指定して /var/lib/mysql2 を初期化
mysql_install_db --datadir /var/lib/mysql2
- /etc/init.d/mysqlのdatadirの記述の部分を、/var/lib/mysql2に変更
# Set some defaults datadir=/var/lib/mysql2
- /etc/my.cnfの、「innodb_force_recovery = 3」を消してmysqlを起動
/etc/init.d/mysql start
- 新しいmysqlに、DBを作って、ダンプしたデータをロード
mysqladmin create databasename; mysql databasename < databasename.sql