RSS

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

10 Nov

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.

 

Referenced by: http://boriskuzmanovic.wordpress.com/2008/11/26/mamp-error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-tmpmysqlsock-2/

About these ads
 
Leave a comment

Posted by on November 10, 2011 in MySQL Server

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: