Tue 29 Jan 2008
Mysql 5 client from MacPorts and Server from Official Package
Posted by mike under Computer Stuff
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
-S /tmp/mysql.sock
to your mysql5 command to use it without any configuration (i.e. changing the location of the socket).