MySQLのテーブルが壊れた

エラー: データベースに接続できません

WordPressのトップにたった一行でかでかと表示されてた。ブレーカーが落ちたせいだな。

WordPress側から復元とかできる仕組みがあるらしいけど、うまく動かなかった。エラーメッセージ的にMySQLの方の問題だろうと思って、コマンドラインで試してみるとデータベースには普通に繋がる。とりあえず片っぱしからアクセスしてみると、

mysql> select * from wp_options;
ERROR 145 (HY000): Table './wordpress/wp_options' is marked as crashed and should be repaired

初めて見たエラーだけどググったら速攻で出てきたので何とかなりそう。それにしてもエラーメッセージがおかしい。「テーブルを読み取れません」とまで分からなくても「データベースに問題があります」程度にしてくれないと原因究明し辛い。

mysql> check table wp_options;
+----------------------+-------+----------+-----------------------------------------------------------------------------------------+
| Table                | Op    | Msg_type | Msg_text                                                                                |
+----------------------+-------+----------+-----------------------------------------------------------------------------------------+
| wordpress.wp_options | check | error    | Table upgrade required. Please do "REPAIR TABLE `wp_options`" or dump/reload to fix it! |
+----------------------+-------+----------+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> repair table wp_options;
+----------------------+--------+----------+------------------------------------------------------+
| Table                | Op     | Msg_type | Msg_text                                             |
+----------------------+--------+----------+------------------------------------------------------+
| wordpress.wp_options | repair | info     | Wrong bytesec:  58- 34- 34 at 296176; Skipped        |
| wordpress.wp_options | repair | info     | Found block that points outside data file at 7572    |
| wordpress.wp_options | repair | info     | Found block with too small length at 194732; Skipped |
| wordpress.wp_options | repair | info     | Found block that points outside data file at 194744  |
| wordpress.wp_options | repair | info     | Found block that points outside data file at 204696  |
| wordpress.wp_options | repair | info     | Found block that points outside data file at 207436  |
| wordpress.wp_options | repair | info     | Found block that points outside data file at 207532  |
| wordpress.wp_options | repair | info     | Found block that points outside data file at 217276  |
| wordpress.wp_options | repair | info     | Key 1 - Found wrong stored record at 244464          |
| wordpress.wp_options | repair | info     | Found block that points outside data file at 246936  |
| wordpress.wp_options | repair | info     | Found block that points outside data file at 297132  |
| wordpress.wp_options | repair | warning  | Number of rows changed from 161 to 150               |
| wordpress.wp_options | repair | status   | OK                                                   |
+----------------------+--------+----------+------------------------------------------------------+
13 rows in set (0.48 sec)

なんとかなった。

簡単なWordPress高速化

ググればいくらでも出てきたので敢えて俺が書く必要もあるまいて。自分用健忘録。

WordPress を高速化する5つの方法

MySQLのキャッシュ有効化。

$ sudoedit /etc/mysql/my.cnf
# in section [mysqld]
> query_cache_size=24M
$ sudo rc-config restart mysql

PHP拡張APC(中間コードキャッシュ)。

$ sudo emerge pecl-apc
$ sudo rc-config reload apache2

終わり。うっわ簡単。これだけでおよそ描画開始までの遅延が半分にw