Baking in Mac OS: mysql.sock error

by kiawin

Bake your cakephp via Mac OS X without a standard mysql installation might pose some issues.

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Applications/XAMPP/xamppfiles/htdocs/apps/cake/libs/model/datasources/dbo/dbo_mysql.php on line 540

I’m running XAMPP (or maybe MAMP for you) that has mysql.sock located in the wrong place. To resolve this issue, we can just symlink the xampp location (/Applications/XAMPP/xamppfiles/var/mysql) back to mysql default location (/var/mysql).

sudo mkdir /var/mysql

sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock /var/mysql/mysql.sock

Happy baking! :)