Mac OS X: Trouble with MAMP MySQL
MAMP is for Mac what XAMPP is for windows: A very easy-to-use, but Mac-like web development solution. Everything worked out-of-the box as it should - until I tried to install Wordpress on my MacBook. I got a database connection error very early during the Wordpress installation process.
So I tried to talk to the mysql server with the mysql command line tool and got this error message:
macbook:~ sf$ /Applications/MAMP/Library/bin/mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
This was strange as the mysql server was indeed running; I could verify this by an ps command. Futhermore phpMyAdmin, as provided by MAMP, worked flawlessly. Doing some Google research told me that the problem was connected with the location of mysql.sock.
Running ps -awwx | grep mysql showed, that mysqld had been started by MAMP with the option --socket=/Applications/MAMP/tmp/mysql/mysql.sock, whereas the mysql tool and Wordpress assume the socket file here: /tmp/mysql.sock.
With this information the solution is easy:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
This creates a symbolic link from the location expected by mysql and wordpress to the location where the socket file resides. Now I can access my mysql server with the mysql command line tool and my local Wordpress installation can also talk to the database.

Save This Page
[…] Mac OS X: Trouble with MAMP MySQLMAMP is for Mac what XAMPP is for windows: A very easy-to-use, but Mac-like web development solution. Everything worked out-of-the box as it should - until I tried to install Wordpress on my MacBook. I got a database connection error very early during… […]
[…] socks, sockets and sudo’s - something i really don’t care or want to learn. Thankfully, the fix was simple, but virtually impossible to guess or work out the solution for oneself. I thought using […]
thanks for the help Stefan - this is really helpful!
Can anyone tell me how the above fix can be remembered after each re-boot? at the moment i have to re-run the sudo command every time i start up the OS. Any help, or pointers greatly appreciated!
Hi, I’m very interested about this topic.
I’m a new “Mac-User” and I need to use my laptop as a local server for php pages.
I have installed MAMP 1.7: everything works fine using the following ports:
Apache: 8888
MySQL: 8889
The problem is when I try to create a new connection to the database using Dreamweaver CS3: if I use these parameters
Connection name: my_connection
Server: localhost:8888
Username: root
Password: root
Database: my_database
I have the following error message: “MySQL Error#: 2003 - Can’t connect to MySQL server on localhost (10061)”
All the parameters are correct: if I edit an test a php page like this:
everything is ok.
Why Dreamweaver can’t find MySQL connection?
I hope someone can help me.
Thank you in advance!
Genius! Thank you for working this problem out, it had been bothering me for a long time now.
Andrea,
you wrote your MySQL-Server listens on port 8889, but your Dreamweaver configuration tries to access the database server on port 8888 - which is the Apache server and not the MySQL server. Try to use localhost:8889.
Thank you!!! Now it works!!!
Andrea
Thanks for the tip!
I have tried the tip that you have provided, and it worked for a few of the accounts I manage on our Xserve, but not others. After creating the alias, it works for the root account, admin account, and one of the other user accounts, but all the others I have tested so far give me the old error I was receiving prior: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (13). Any suggestions?
Nevermind, I figured it out =) It was simply a mixture of cap-sensitivity between a few users and their database names, and file-permission settings on the /Applications/MAMP/tmp directory.
THANK YOU.
Helped me get to sleep tonight
Thanks for that. Seems to work when trying to use PEAR DB::connect - when the MAMP path directly wouldnt seem to… but I may just be crazy.
Thanks! This was an easy fix for me thanks to you.
Hi!
I tried this, but after running that line I assumed i could type:
mysql -h hostname etc…
but i get
-bash: mysql: command not found
Its probably amazingly simple, but im new to command line stuff on the Mac….
oh, its oK!
worked it out
Anyway, great fix, thanks!
i tried this on OS 10.5 but it still gives me the command not found error when i try and do a command line mysql command. any ideas?
Command not found is another kind of error. Did you try to invoke the mysql command with the complete path, e.g. /Applications/MAMP/Library/bin/mysql? If you just want to type mysql to start the command line tool, then you have to put your /Applications/MAMP/Library/bin directory into your default path.
[…] for me Stefan Fischerländer already found out how to solve […]
Thanks for interesting post
Thanks a lot ! I have been looking during two days on the net to find a solution to that very problem. I found your post… and it works !
Thanks
Nico
thanks for this - saved me hours of headache - particularly on data imports
I’ve run into an error trying to start MySql:
080826 09:38:04 mysqld started
080826 9:38:04 [ERROR] /Applications/MAMP/Library/libexec /mysqld: unknown option ‘–skip-federated’
080826 09:38:04 mysqld ended
I don’t suppose anyone else has seen this?
Thanks!
Cliff
Easy solution:
When you configure connection in CocoaMySQL you have field called “Socket”. Now when you launch your MAMP start page it tells you to use UNIX socket: /Applications/MAMP/tmp/mysql/mysql.sock.
I pasted that socket into Socket field and it worked for me
better
/Applications/MAMP/Library/bin/mysql -uroot -p
than
/Applications/MAMP/Library/bin/mysql -u root -p
Just to say Thanks!!!
=D
Thanks !
It saved me a day !
Thank you! Really helped me!
Hi. I am using a macintosh and I am having troubles with my MAMP. I have just recently downloaded it and the mySQL light won’t come on when I go to start the servers. Apache is the only light that comes on. Please somebody help me!
Brilliant! Thanks for the great tip.
Suddenly after making changes in phpMyAdmin to some tables, I can no longer connect to MAMP start page. Now: Error: Could not connect to MySQL server! is what I see. I have tried to change MySql Port to 3306, back to 8889. Also, have attempted various terminal commands. Viewing my index.php (Applications/MAMP/bin/mamp) as i read in previous post has: $link = @mysql_connect(’:/Applications/MAMP/tmp/mysql/mysql.sock’, ‘root’, ‘root’);
Any thoughts? Maybe I changed username/password from phpMyAdmin? please help
okay,
so i deleted and reinstalled MAMP with success in launching start page. hope this helps.
Thanks a lot. This article saved me.
Cheers Dude,
you saved me from a massive headache. I had the issue while debugging php/mysql stuff with Aptana and MAMP.
The symbolic link saved it! I have the feeling that people trying to do the same with Zend Studio would love you too.
May be you’d like to post an update to this one.
By the way don’t listen to the loosers afraid by command line stuff, Mac OS is UNIX and it’s powerful
Take care
Yes, the solution works! Thanks a lot!!!
Holy Shit! You just ended a two day, no holds barred throwdown between me and MAMP MySQL. Now I can finally get some work done. Thank You!
Thank you. Ran into the exact same problem with my MAMP installation. Now it works like a charm!
Hi - I’m new to this, fyi
I opened terminal and executed:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
I assumed this was the way to fix the issue. But… it still doesn’t work. I’m running OS X 10.5.6. When I go to localhost:8888/wordpress/ I’m still getting “Error establishing a database connection”.
Did I do this incorrectly?
Thanks, works like a charm!
Just one thing:
Like Matt said at the moment i have to re-run the sudo command every time i start up the OS.
Is there a way how I could make this link permanent???
Thanks!
[…] in the default location, not wherever MAMP’s mySQL server is. One solution, which I found here, is to put a symbolic link in the place where the library looks, which points to the real file in […]
Wow, thanks man! Solved my problem with Sequel Pro!
it seems i have to do this every time i fire up my mac. Is there a way to script this and have that script run on startup?
thanks
M
Guys, the mysql.sock file gets created when MAMP is started and is deleted when MAMP is stopped, that’s why it’s in /tmp/ - because it’s temporary. Creating an alias to this file works, but when the original is deleted, the alias is also removed.
A more permanent solution is to edit Mamp’s configuration files:
/Applications/MAMP/bin/startMysql.sh and
/Applications/MAMP/bin/stopMysql.sh
Just replace
socket=/Applications/MAMP/tmp/mysql/mysql.sock
with
socket=/tmp/mysql.sock
I have been trying to connect MySQL WorkBench (MWB) for Mac but not joy.
My local host is ok and can connect to DB in shell
1) tried the symlink solution but couldn’t connect with Error (61) that cannot connect
2) changed paths in MAMPs menu (changing those files in MAMP folder does noting) in File > Edit templates > MySQL my.conf, then php5.ini and so on -> didn’t work (after restart)
3) changed PATH/MAMP/bin/startMysql.sh and stopMysql.sh -> didn’t work when reloaded MAMP
IT ONLY WORKED when I killed processes and run those files manully in shell then was able to connect to MWB.
There used to be socket custom field in Mysql Browser that allowed to connect to socket in a different location. No such thing in MWB anymore. Why? don’t ask me - left feedback on MySQL forums asking for answers.
Things might stop working if you just change paths as described above because php.ini and many other scripts have this path to mysql.sock set to your MAMP folder. Just run in your MAMP this command to see how many:
egrep -alR –regexp=”/tmp/mysql/mysql.sock” *
Thanks,this post just help me much.
I have MAMP running on a Mac Mini on my local network. I’ve set up an ODBC connection to the MySQL database using the MySQL ODBC 5.1 driver and it connects fine using the localhost/port 8889/Applications/MAMP/tmp/mysql/mysql.sock settings.
However, when I try to set up an ODBC connection from my MacBook to the same mysql db on that machine, I get an error: “Request Returned with SQL Error” I’m guessing this has to do with how I’m referencing the port . . .
Any suggestions?
Thanls a lot for the symbolic link tip.
Simple, easy and effective.
SeeYa!
Djio
Thank you! Perfect! I’ve been stuck with this problem so many times!
thanx for that one!