Stefan Fischerländer’s Blog One Blog Is Not Enough

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.

24 Responses to “Mac OS X: Trouble with MAMP MySQL”

  1. » Blog Archive » Mac OS X: Trouble with MAMP MySQL says

    […] 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… […]

  2. I thought using a Mac was supposed to be simple? | The Social Publishing Blog says

    […] 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 […]

  3. Matt says

    thanks for the help Stefan - this is really helpful!

  4. Matt says

    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!

  5. Andrea says

    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!

  6. Rob says

    Genius! Thank you for working this problem out, it had been bothering me for a long time now.

  7. Stefan says

    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.

  8. Andrea says

    Thank you!!! Now it works!!!
    Andrea

  9. Todd says

    Thanks for the tip!

  10. Matt says

    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?

  11. Matt says

    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.

  12. Michael says

    THANK YOU. :-)

  13. Andrew Maier says

    Helped me get to sleep tonight :)

  14. firecall says

    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. :)

  15. Mark Tourtellott says

    Thanks! This was an easy fix for me thanks to you.

  16. roosta says

    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….

  17. roosta says

    oh, its oK!

    worked it out

    Anyway, great fix, thanks!

  18. JD says

    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?

  19. Stefan says

    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.

  20. Mike’s Blog » Blog Archive » MAMP + Aptana with radrails says

    […] for me Stefan Fischerländer already found out how to solve […]

  21. mike says

    Thanks for interesting post

  22. Nico says

    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

  23. Matthew says

    thanks for this - saved me hours of headache - particularly on data imports

  24. cliff says

    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

Leave a Reply