Hugh Hunter

Hacking his way through the weeds,

Connecting MySQL Command Line Client to MAMP on OSX

| Comments

I’ve been coming around lately to the local development environment vs doing all of my development on a remote server. The last thing I moved onto my laptop was MySQL and I am used the popular (and free) tool MAMP to get it running quickly.

However, as I am a fan of the MySQL command-line client, I went to test my installation by running:

$ mysql -uroot -p

I expected a connection to the server running on localhost. What I got was an error:

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

It turns out that MAMP sets up its unix socket in /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock rather than in /tmp/mysql.sock (where the MySQL command line client looks for it. Rather than passing in a messy --socket option to mysql, I opted for the following, which did the trick:

$ sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock