0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rails new時のMySQLのエラーについて

Posted at

(2020/03/08 執筆中)

きっかけ

rails new --api -d mysql実行時に以下のエラーが出たので、自分なりにまとめておきます。

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)
MySQL server PID file could not be found!

バージョン

$ rails -v
Rails 6.0.2.1

$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) 

$ mysql -v
mysql  Ver 8.0.19 for osx10.14 on x86_64 (Homebrew)

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

これは、/tmp/mysql.sockがないというメッセージ。
いろいろ試してみてわかったのは、MySQLが起動していないと/tmp/mysql.sockはつくられないということ。
なので、Mac立上げ時に自動起動を設定していない人には辛いエラーかもしれません。

# /tmp/フォルダ内部を確認
$ ll /tmp/
# mysql.sockがない
drwx------  3 user_name  wheel    96B  3  3 10:03 com.apple.launchd.xxxxxxx
drwx------  3 user_name  wheel    96B  3  3 10:03 com.apple.launchd.xxxxxxx
drwxr-xr-x@ 3 user_name  wheel    96B  3  8 08:43 com.google.Keystone

# MySQLが起動しているか確認
$ mysql.server status
 ERROR! MySQL is not running

# MySQLを起動
$ mysql.server start
Starting MySQL
. SUCCESS! 

# もう一度/tmp/フォルダ内部を確認
$ ll /tmp/
# mysql.sockが存在する
total 16
drwx------  3 user_name  wheel    96B  3  3 10:03 com.apple.launchd.xxxxxx
drwx------  3 user_name  wheel    96B  3  3 10:03 com.apple.launchd.xxxxxx
drwxr-xr-x@ 3 user_name  wheel    96B  3  8 08:43 com.google.Keystone
srwxrwxrwx  1 user_name  wheel     0B  3  8 12:03 mysql.sock
-rw-------  1 user_name  wheel     6B  3  8 12:03 mysql.sock.lock
srwxrwxrwx  1 user_name  wheel     0B  3  8 12:03 mysqlx.sock
-rw-------  1 user_name  wheel     7B  3  8 12:03 mysqlx.sock.lock

権限がどうこうという記事を見ますが、その前に、MySQLが起動しているかを確認しましょう。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?