LoginSignup
98
98

More than 5 years have passed since last update.

mysqlを起動しようとしたらPIDファイルがnot foundで起動できないのを解決する話

Last updated at Posted at 2015-09-20

寝落ちしたらいつの間にかターミナルとか色々落ちててmysqlに入れなくなったときの対処記録。
なんども直面している問題なので、いい加減自分の中に解決方法をストックしておきたい。

1.エラー内容を多角的に捉える

そもそも

ERROR! MySQL server PID file could not be found!

というエラーを吐くのは、mysql.server restartしようとするときの話。
この状態のままでは、このエラー文しか見れていない。しかし、

$ mysql -u root -p
Can't connect to local MySQL server through socket '/tmp/mysql.sock'

というようにエラー文が変わる。実際にエラーが起きている事実は変わらないが、ググるときの検索キーワードが増えることになります。

2.エラーのログをよく読む

このエラーが起きているときには、毎回 /usr/local/var/mysql/~.errorというところにログが入っています。なので、まずはそのログをよく読む。いや、よくは読まなくてもいいのでそこに出ているエラー文を検索キーワードとして使うという心意気を持っておく。これで検索する上でのフル装備が整うわけです。

ちなみに今回のエラー文は以下のもの

InnoDB: Error: could not open single-table tablespace file .\bbs2_training_development\comments.ibd

InnoDB: We do not continue the crash recovery, because the table may become

InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.

InnoDB: To fix the problem and start mysqld:

InnoDB: 1) If there is a permission problem in the file and mysqld cannot

InnoDB: open the file, you should modify the permissions.

InnoDB: 2) If the table is not needed, or you can restore it from a backup,

InnoDB: then you can remove the .ibd file, and InnoDB will do a normal

InnoDB: crash recovery and ignore that table.

InnoDB: 3) If the file system or the disk is broken, and you cannot remove

InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf

InnoDB: and force InnoDB to continue crash recovery here.

3.ググる

1., 2.で検索する視点を2つ持てたので、それに従って両方を検索すれば色々出てくるわけです。

書き込み権限があるか確認

今回はこれで済みました。
まず、/usr/local/varに移動します。そして、ls -llでmysqlディレクトリの権限を確認します。
あれ?mysqlになっているじゃん、と。

これを自分のユーザー名にしてしまえば解決できました。

$ sudo chown -R [ユーザー名] mysql

ここで、-Rをいれることを忘れないでください。ディレクトリ全体に適応するには、これがないとだめなので。

途中のプロセスを切る

mysql pid not foundで検索してくるとすぐに出てくるやつですね。

$ ps ax | grep mysql

で途中になっているプロセスがないかどうか確認して、あったらkillする、と。
僕はこれにぶち当たったことはまだないですけど。

4823 s000  R+     0:00.00 grep mysql

てな感じで、検索に使ったのが出てくるだけでした。

まとめ

mysqlのエラーが出ても、一つのエラー文のみに固執せず、他にいろいろなエラーがないか探したり、段階的にエラーをおこしてログが変わるのを期待したりするのがいいすね。

98
98
2

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
98
98