Fixing the mysql.sock not found error on MAMP

Cakephp logo

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:

[box] 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][/box]

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

[box] sudo mkdir /var/mysql

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

 

Now go back and have a happy bake 🙂

44 comments

  1. JDR   •  

    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.

    • Mostafaberg   •     Author

      I’m glad it helped, it took me sometime to figure it out 🙂

  2. Pingback: I’ve been having problems hooking CakePHP into MAMP… « « Jay Margalus Jay Margalus

  3. 3cents   •  

    thanks a lot !!!

  4. Octavian   •  

    Thanks a million man!

  5. Frank   •  

    Thanks Berg! much appreciated.

  6. Pingback: Scheduled Tasks in SilverStripe | Deadly Technology

  7. Bruno   •  

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

  8. Guins   •  

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

  9. Ilie Pandia   •  

    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

  10. Ilie Pandia   •  

    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 🙂

  11. Sam   •  

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

  12. Ibrahim Azhar Armar   •  

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

  13. Ibrahim Azhar Armar   •  

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

  14. Vick   •  

    You are a genius, thanks mate!

  15. Tamil   •  

    Thank You very much

  16. Fiqri   •  

    Thanks a lot , saved me loads of time 🙂

  17. Gippy   •  

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

    • Berg   •     Author

      Oh thanks a lot for the tip !

  18. Paulo Rodrigues   •  

    Thanks a lot! 🙂

  19. John Erck   •  

    Thanks.

  20. Ryan   •  

    Thanks for this. Got to love the simple fixes.

  21. Mo   •  

    WOW that was easy!

  22. Anonymous   •  

    Thanks a lot 🙂 Helped so much !

  23. MidnightFistFight   •  

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

  24. Dodg3r   •  

    Thanks mate. Exactly what i was looking for 🙂

  25. mohammed   •  

    Legend!!!!!

  26. Marc   •  

    Very nice, thanks!

  27. Neokio   •  

    Thank you FTW!!!

  28. hiroyuki kiyomizu   •  

    thanks a lot !!!
    Good job

  29. Rana   •  

    Thanks a lot. You saved my day 😀

  30. Sergei   •  

    Thanks man!!!

  31. Nolan   •  

    Thanks a ton! Been struggling with this for hours.

  32. makkus   •  

    perfect, thank you!

  33. Esdras   •  

    Muitissimo Obrigado!
    Resolveu meu problema.

  34. Darshan Joshi   •  

    Darshans-MacBook-Air-2:~ Darshan1$ sudo mkdir /var/mysql
    Password:
    Sorry, try again.
    Password:
    Sorry, try again.
    Password:

    what to type in password ??

    mysql.sock not showing in folder 🙁 please help

  35. zee   •  

    it is 2017 and this just helped me loads!!

Leave a Reply

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