Hugh Hunter

Hacking his way through the weeds, the.dudeabid.es

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:

1
$ mysql -uroot -p

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

1
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:

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

Comments