Help us understand the problem. What is going on with this article?

RailsでMySQL serverでsocketのerrorが出た時

More than 3 years have passed since last update.

僕の場合は、Mac上のdevelopment環境で、複数DB serverを立ち上げて、Railsから複数DBに接続しようとした場合に発生したのですが、
Railsでdatabaseとのconnecing時に、
Can't connect to local MySQL server through socket
のようなsocket fileに関連するErrorが発生しました。

例えばCan't connect to local MySQL server through socket '/tmp/mysql.sock1'というErrorが発生したとき,Railsは/tmp/mysql.sock1に接続しにいこうとしたけど,接続できなかったということです。

my.cnfで指定したsocket fileをrailsで指定してるのになと思ってたのですが、Error messageから推察するに、mysqlのsocketがRailsで指定した/tmp/mysql.sock1ではない可能性が高いです。

なので、mysqlのsocketがまずどこにあるか調べてみます。

sudo mysqladmin -p version

と打つと、mysql serverに関する情報が表示されます。

mysqladmin  Ver 8.42 Distrib 5.6.26, for osx10.10 on x86_64
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version      5.6.26
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /tmp/mysql.sock
Uptime:         12 hours 7 min 9 sec

UNIX socketの部分を見ると、mysql serverのsocket fileがpathがわかります。

なので、database.ymlの中身を
socket: /tmp/mysql.sockと指定し直してあげると
workします。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした