Fixing the “unix:///var/mysql/mysql.sock” not found error on MAMP

Fixing the “unix:///var/mysql/mysql.sock” not found error on MAMP

I’ve recently been working on a CakePHP project on my Mac, I’ve noticed that when
I tried Baking the project, This error came out:

Warning Error: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in [/Users/xxxxx/Projects/public_html/xxxxxx/lib/Cake/Model/Datasource/Database/Mysql.php, line 157]

After a lookup, seems lots of people seem to come through this when working on MAMP
so to fix that, start your terminal and create a link to “mysql.sock” manually

sudo mkdir /var/mysql

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

 

Now go back and have a happy bake :)

32 Comments

  1. Thanks a lot!

    I was trying to run many php files from the command line and didn’t know the reason why it was showing up some errors when sql statements were run. It took me days until I found out your simple but smart solution. :)

    I assume that php is looking for a path that would be by default if mysql was installed individually and not as part of MAMP as it was my case. Linking a new folder with the active one used by MAMP is a great idea.

  2. thanks a lot !!!

  3. Thanks a million man!

  4. Thanks Berg! much appreciated.

  5. oh man, thanks mate…. 1 command and you solved 2 days of arguments… :)
    Thanks a lot

  6. Thanks a lot, first search on facebook, just perfect !

  7. Hello,

    Instead of creating a link I think is better to configure the location of the socket in php.ini

    Open the php.ini you’re using with MAMP, look for [Pdo_mysql] and right under that you should find a line like this:

    pdo_mysql.default_socket=/var/mysql/mysql.sock

    Comment out that line (if not commented already) and then add the new location of the mysql.sock

    pdo_mysql.default_socket=/Applications/MAMP/tmp/mysql/mysql.sock

    Note: If do NOT use MAMP the most likely location on Mac for mysql.sock is /tmp/mysql.sock

  8. I forgot to add that you need to restart you Apache server to pick up the change in php.ini otherwise it won’t work :)

  9. I love you so much! I have been searching on how to fix this for a long bloody time!
    Much appreciated.

  10. I had problem using Doctrine CLI with Doctrine framework and gave me similar error message. thanks mate that command solved my problem

  11. I had problem using Doctrine CLI with Zend framework and gave me similar error message. thanks mate that command solved my problem

  12. You are a genius, thanks mate!

  13. Thank You very much

  14. Thanks a lot , saved me loads of time :)

  15. Watch out … the Apple security update can wipe out the link

  16. Paulo Rodrigues |

    Thanks a lot! :)

  17. Thanks.

  18. Thanks for this. Got to love the simple fixes.

  19. Thanks!!!

    Very usefull!!

  20. WOW that was easy!

  21. Thanks a lot :) Helped so much !

  22. MidnightFistFight |

    Man — I just spent the past three hours of my life trying to find the solution to this problem. Fixed me right uP!

  23. Thanks mate. Exactly what i was looking for :)

  24. Legend!!!!!

  25. Very nice, thanks!

  26. Thank you FTW!!!

  27. hiroyuki kiyomizu |

    thanks a lot !!!
    Good job

  28. Thanks a lot. You saved my day :D

Trackbacks/Pingbacks

  1. I’ve been having problems hooking CakePHP into MAMP… « « Jay Margalus Jay Margalus - [...] http://www.mostafaberg.com/2011/08/fixing-the-unixvarmysqlmysql-sock-not-found-error-on-mamp/   [...]
  2. Scheduled Tasks in SilverStripe | Deadly Technology - [...] “unix:///var/mysql/mysql.sock” not found My task could not connect to the database, because the mysql.sock file could not be found. ...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>