Skip to content

Instantly share code, notes, and snippets.

@cristiancorreau
Created April 2, 2013 22:06
Show Gist options
  • Save cristiancorreau/5296645 to your computer and use it in GitHub Desktop.
Save cristiancorreau/5296645 to your computer and use it in GitHub Desktop.
MAMP: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I instaled MAMP and it worked great. However, when I tried to access mysql from the shell I was getting
$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
However, using a full path to MAMP binary worked.
$ /Applications/MAMP/Library/bin/mysql -u root -p
MAMP’s mysql works with another socket file which is located at /Applications/MAMP/tmp/mysql/mysql.sock
All you have to do is:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
UPDATE: As it turns out the above soft link gets erased by the system, so you need to run the command every once in a while. At one point it got too frustrating so I figured out a permanent way to take care of this problem. Open /etc/my.cnf and add/edit these lines:
[mysqld]
socket=/Applications/MAMP/tmp/mysql/mysql.sock
[client]
socket=/Applications/MAMP/tmp/mysql/mysql.sock
Instead of telling MAMP which socket file to use, you are instructing the mysql client to use MAMP’s default socket.
Let me know if this works for you.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment