CakePHP Shell Not Seeing MySQL with MAMP Pro MAC
MAMP is a great product. It makes using the MAMP stack on MAC very easy. I liked it so much I actually purchased MAMP Pro. Installing was a breeze, configuration is simple, and it is up and running in no time. However, for some reason, when I am trying to connect to MySQL from a CakePHP shell, the database connection cannot be found.
The error I was getting was:
Warning: mysql_connect(): [2002] No such file or directory (trying to
connect via unix:///tmp/mysql.sock) in /Users/myuser/Sites/cakephp/cake/libs/model/datasources/dbo/dbo_mysql.php
on line 540
So I had to figure out what the issue was and resolve it. The solution was very simple. The error gives a clue. It turns out that CakePHP is looking for the mysql socket in /tmp. However, MAMP is running the socket in /Applications/MAMP/tmp. We just have to symbolically link the socket that CakePHP is looking for to the actual socket MySQL is running on in MAMP. This can be accomplished with the following command after MAMP Pro is running:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
This will resolve the issue and MAMP will run as expected for CakePHP shell applications. I hope this helps.
Happy Coding!









>
Follow Me (digitally you stalker)