I just noticed that when you use the mysql 5 client from MacPorts (installed as /opt/local/bin/mysql5) to connect to a mysql5 server running on localhost that was installed via the package at dev.mysql.com, an error is generated:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (2)
This is because the installation of mysql 5 server from the mysql site uses /tmp to hold the socket file. Of course if you read the README you’d know this:
“The installation layout is similar to that of a `tar’ file binary
distribution; all MySQL binaries are located in the directory
`/usr/local/mysql/bin’. The MySQL socket file is created as
`/tmp/mysql.sock’ by default.”
I, of course, did not read the README first, and so I wondered what I was doing wrong. The fix is easy, just add
to your mysql5 command to use it without any configuration (i.e. changing the location of the socket).
And what happens if I can start the server locally, run mysql -uroot -ppassword, successfully log in.
Then I stop my local mysql server.
Setup a tunnel to my server with
ssh -L 3306:localhost:3306 user@serveraddress
run mysql -uroot -ppassword -S /tmp/mysql.sock
And I still get that stupid error:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
Sounds like your mysql client is trying to access via /tmp/mysql.sock instead of via network, this could be for any number of reasons. I’ve been using mysql from homebrew and had no problems connecting at all. That’s not really a solution, I know. Try starting the mysql client with options that tell it the server name (-h) and tell it the server is localhost, that should coerce it into trying via network instead of local socket, if that’s what you really want.
Leave a comment