端くれプログラマの備忘録 MySQL [MySQL] 壊れたテーブルを修復する

[MySQL] 壊れたテーブルを修復する

前のエントリで書いた通り、突然サーバーが高負荷になって何も受け付けなくなったので、仕方なくシャットダウン。再起動後にログを見回ったら、MySQL (実体はMariaDB) のログにエラーが記録されていた。やばい予感。

mysqld_safe Number of processes running now: 0
mysqld_safe mysqld restarted
mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[Note] /usr/libexec/mysqld (mysqld 5.5.44-MariaDB) starting as process 1532 ...
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.7
InnoDB: Using Linux native AIO
InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: Completed initialization of buffer pool
InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
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: Waiting for the background threads to start
Percona XtraDB (http://www.percona.com) 5.5.43-MariaDB-37.2 started; log sequence number 13888240
[Note] Plugin 'FEEDBACK' is disabled.
[Note] Server socket created on IP: '0.0.0.0'.
[ERROR] mysqld: Table './mysql/user' is marked as crashed and should be repaired
[Warning] Checking table:   './mysql/user'
[ERROR] mysql.user: 1 client is using or hasn't closed the table properly
[ERROR] mysqld: Table './mysql/db' is marked as crashed and should be repaired
[Warning] Checking table:   './mysql/db'
[ERROR] mysql.db: 1 client is using or hasn't closed the table properly
[Note] Event Scheduler: Loaded 0 events
[Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.44-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
[ERROR] mysqld: Table './db1/wp_options' is marked as crashed and should be repaired
[Warning] Checking table:   './db1/wp_options'
[ERROR] mysqld: Table './db1/wp_posts' is marked as crashed and should be repaired
[Warning] Checking table:   './db1/wp_posts'
[ERROR] mysqld: Table './db1/wp_comments' is marked as crashed and should be repaired

WordPressは問題なく動作しているように見えるけど、念のためリカバリしておいたほうがいいだろう。ということで、エラーチェックとリカバリ用のコマンド (SQL) を覚え書き。

check table <table_name>;
repair table <table_name>;

これらコマンドを実行してみたけど何も起きなかった。起動時に走ったリカバリ処理が問題を解決してくれた模様。大事にならなくて良かったねー

参考サイト

MySQL の壊れたテーブルを修復
http://macperson.net/mysql-table-repair/