LoginSignup
4
3

More than 3 years have passed since last update.

Mysqlに接続できない時のTips

Last updated at Posted at 2019-06-19

エラー内容

Railsの開発中に突然mysqlにアクセスを阻まれる。。orz
Mysql2::Error: Can't connect to local MySQL
よく見るエラーですね。解消しましょう。

#入力コマンド
// mysqlの停止
$ sudo service mysql stop

// セーフモードでmysqlの起動
$ sudo mysqld_safe --skip-grant-tables &
[1] 17586

2019-05-21T07:14:21.943446Z mysqld_safe Logging to syslog.
2019-05-21T07:14:21.948065Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2019-05-21T07:14:21.951694Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

[1]+  Exit 1                  sudo mysqld_safe --skip-grant-tables

'/var/run/mysqld' for UNIX socket file don't exists.
どうやら「ソケットファイルがないよ」と言ったエラーが起きているらしい。

作ろう!

解決コマンド

$ sudo mkdir /var/run/mysqld
$ sudo chown mysql:mysql /var/run/mysqld

接続の確認ができる。
※ときどき、時間が解決する時があって困る。(時間が経つと、mysqlに接続できる)

参考:
MySQLサーバにログインできないとき
stackoverflow

もしかすると...(他に考えられること)

エラー画面
Can't connect to MySQL server on DBサーバー~~~~~
  • DB側でセキュリティグループの設定をしていてIP制限しているかも!
  • セキュリティグループで解放しているwifiに接続し直せばOK
4
3
0

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
4
3