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.

Eb
October 19, 2011 at 8:24 pm
Hi,
I am a complete novice and no nothing about programming but love designing using simple software.
I recently installed the free version of MAMP to create a database. It was working great until I tried changing the default login and pw from “root” to something else. I was then not able to login again so I reinstall MAMP again. After reinstalling, I am able to access the Apache and do everything (change default port, open program etc).
However, when I try to access the mysql using dreamweaver, I get ERROR 2002: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2). I will appreciate your help and please consider it as helping a first grader
Thanks
boriskuzmanovic
October 19, 2011 at 9:05 pm
I think you need to specify your socket location in Dreamweaver. Instead of the default /var/lib/mysql/mysql.sock, set it to /Applications/MAMP/tmp/mysql/mysql.sock
Hope it helps.
Eb
October 20, 2011 at 1:39 am
That is where I am having the challenge. How do I do that? I just tried it in the terminal and got an error message for No such file or directory
Eb
October 20, 2011 at 2:43 am
Now I created my.cnf in the /etc folder with the following code:
[client]
socket = /var/mysql/mysql.sock
[mysqld]
socket = /var/mysql/mysql.sock
Next, I move mysql.sock to it’s new directory by typing the following code in a Terminal window:
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
And when I tried the /Applications/MAMP/tmp/mysql/mysql.sock, I got permission denied
When I tried to get php to communicate with sql I got ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/usr/mysql-5.0/data/mysql.sock’ (2)
boriskuzmanovic
October 20, 2011 at 2:10 am
First of all, make sure that MAMP is running. Open a terminal and type:
sudo ls /Applications/MAMP/tmp/mysql/mysql.sock
This should list your socket file. If you get “No such file or directory”, you may need to fix your my.cnf configuration.
I use MAMP Pro, but it probably is the same. Open MAMP and click on File>Edit template>MySQL my.conf. An editor will open which would allow you to specify the socket. Make sure it points to /Applications/MAMP/tmp/mysql/mysql.sock.
My file has these lines:
[client]
socket = /Applications/MAMP/tmp/mysql/mysql.sock
[mysqld]
socket = /Applications/MAMP/tmp/mysql/mysql.sock
The above is just a snippet of the my.cnf.
When you’re done editing, save the file and restart MAMP services. Try restarting Dreamweaver as well.
Eb
October 21, 2011 at 11:40 pm
I just run
ps -awwx | grep mysql
and I am wondering if you can help interprete it and see if it makes any sense and/or is related to me issue
Last login: Fri Oct 21 19:24:55 on ttys000
eb-obeng-nyarkohs-imac:~ eobeng-nyarkoh$ ps -awwx | grep mysql
618 ?? 0:00.02 /Applications/Adobe Acrobat 8 Professional/Adobe Acrobat Professional.app/Contents/MacOS/mysqld –skip-networking –socket=/Users/eobeng-nyarkoh/Library/Caches/Acrobat/8.0_x86/Organizer70 –skip-grant-tables –skip-innodb –myisam-recover –lower_case_table_names=1 –tmpdir=/Users/eobeng-nyarkoh/Library/Caches/Acrobat/8.0_x86/ –datadir=/Users/eobeng-nyarkoh/Library/Acrobat User Data/8.0_x86/ –language=/Applications/Adobe Acrobat 8 Professional/Adobe Acrobat Professional.app/Contents/MacOS/
684 ttys000 0:00.00 grep mysql
eb-obeng-nyarkohs-imac:~ eobeng-nyarkoh$ ps -awwx | grep mysql
618 ?? 0:00.02 /Applications/Adobe Acrobat 8 Professional/Adobe Acrobat Professional.app/Contents/MacOS/mysqld –skip-networking –socket=/Users/eobeng-nyarkoh/Library/Caches/Acrobat/8.0_x86/Organizer70 –skip-grant-tables –skip-innodb –myisam-recover –lower_case_table_names=1 –tmpdir=/Users/eobeng-nyarkoh/Library/Caches/Acrobat/8.0_x86/ –datadir=/Users/eobeng-nyarkoh/Library/Acrobat User Data/8.0_x86/ –language=/Applications/Adobe Acrobat 8 Professional/Adobe Acrobat Professional.app/Contents/MacOS/
689 ?? 0:00.03 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe –port=8889 –socket=/Applications/MAMP/tmp/mysql/mysql.sock –lower_case_table_names=0 –pid-file=/Applications/MAMP/tmp/mysql/mysql.pid –log-error=/Applications/MAMP/logs/mysql_error_log
808 ?? 0:00.15 /Applications/MAMP/Library/bin/mysqld –basedir=/Applications/MAMP/Library –datadir=/Applications/MAMP/db/mysql –plugin-dir=/Applications/MAMP/Library/lib/plugin –user=mysql –lower-case-table-names=0 –log-error=/Applications/MAMP/logs/mysql_error_log.err –pid-file=/Applications/MAMP/tmp/mysql/mysql.pid –socket=/Applications/MAMP/tmp/mysql/mysql.sock –port=8889
834 ttys000 0:00.00 grep mysql
Eb
October 25, 2011 at 2:32 am
When I type
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
and Password:
I got
ln: /tmp/mysql.sock: File exists
When I type
sudo ls /Applications/MAMP/tmp/mysql/mysql.sock
I got
/Applications/MAMP/tmp/mysql/mysql.sock
The latest development is that I have now switched from the free version to pro and when I opened m.cnf file i see the following which is the same as what you suggested I change to
[client]
#password = your_password
#port = 9999
socket = /Applications/MAMP/tmp/mysql/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
#port = 9999
socket = /Applications/MAMP/tmp/mysql/mysql.sock
Eb
November 5, 2011 at 1:31 am
Finally figured it out after trying with everything. I tried so many things out there that I cannot even remember which one it was that work … but I added “#” to a line in my.cnf
boriskuzmanovic
November 5, 2011 at 1:59 am
I’m glad you sorted it out. Cheers!
sochinda
November 10, 2011 at 5:34 am
May I re-post this topic into my blog?
I hope you will let me to do, thanks in advanced.
Jose Apolloe
May 19, 2012 at 10:20 pm
thanks works great
max li bin (@maxlibin)
April 22, 2013 at 3:35 am
problem solved! thanks