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

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 !