DB接続エラー

毎朝の日課として自分のホームページを開いたところ、

dberror

えぇ!どうなってんの?いきなりダメです。
DBが壊れてるの?
こういうときは慌てず騒がず、きちんと原因の切り分けを行います。

①まずはブラウザのキャッシュをクリアし確認 → ダメ。エラーのまま
②別回線からの確認。自宅ネットでなくスマホの4Gで確認 → ダメ。エラーのまま
③Apacheの再起動 → ダメ。エラーのまま
④別のDBを使っているアプリは動いているか? → これは正常。となるとDBサーバーは大丈夫。どうもホームページのDBだけがまずいみたい。

やばいとりあえず何か操作する前にバックアップをとっておこう。

[root]# mysqldump -uroot -p wordpress > 20150625_wordpress.sql                               
Enter password:                                                             
mysqldump: Got error: 145: Table './wordpress/wp_options' is marked as crashed and should be repaired when using LOCK TABLES

え!壊れてる!って。バックアップもとれないのか!

かなり動揺しました。ググってみるとデータベースの状態チェック、確認コマンドを発見。まずは状態を確認します。

[root]# mysqlcheck -c wordpress wp_options -uroot -p
Enter password:
wordpress.wp_options
warning : Table is marked as crashed
warning : 3 clients are using or haven't closed the table properly
warning : Found 614960 deleted space in delete link chain. Should be 615284
error : Found 298 deleted rows in delete link chain. Should be 299
error : record delete-link-chain corrupted
error : Corrupt
[root]#

やっぱり壊れてるって・・・

次に修復コマンドを試します。

[root]# mysqlcheck -r wordpress wp_options -uroot -p
Enter password:
wordpress.wp_options
warning : Number of rows changed from 327 to 325
status : OK

治ったの??再度、状態を確認しました。

[root]# mysqlcheck -c wordpress wp_options -uroot -p
Enter password:
wordpress.wp_options OK
[root]#

 

よしよしよし、じゃぁブラウザから見てみよう。

dberror2

 

やった!治った!

この後、すかさずDB全バックアップをとったのはいうまでもありません。

ほんと怖い経験でした。

Copyright© ちえてらすコンサルティング , 2024 All Rights Reserved.