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
Trackbacks/Pingbacks
- 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/ [...]
- 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. ...

Game developer,
Web developer,
Car enthusiast,
hacker,
geek,
youtube troll 
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.
I’m glad it helped, it took me sometime to figure it out
thanks a lot !!!
Thanks a million man!
Thanks Berg! much appreciated.
oh man, thanks mate…. 1 command and you solved 2 days of arguments…
Thanks a lot
Thanks a lot, first search on facebook, just perfect !
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
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
I love you so much! I have been searching on how to fix this for a long bloody time!
Much appreciated.
I had problem using Doctrine CLI with Doctrine framework and gave me similar error message. thanks mate that command solved my problem
I had problem using Doctrine CLI with Zend framework and gave me similar error message. thanks mate that command solved my problem
You are a genius, thanks mate!
Thank You very much
Thanks a lot , saved me loads of time
Watch out … the Apple security update can wipe out the link
Oh thanks a lot for the tip !
Thanks a lot!
Thanks.
Thanks for this. Got to love the simple fixes.
Thanks!!!
Very usefull!!
WOW that was easy!
Thanks a lot
Helped so much !
Man — I just spent the past three hours of my life trying to find the solution to this problem. Fixed me right uP!
thank you !
Thanks mate. Exactly what i was looking for
Thanks. Nice post …
Legend!!!!!
Very nice, thanks!
Thank you FTW!!!
thanks a lot !!!
Good job
Thanks a lot. You saved my day