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!

Like it? Post to your favorite location and share.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Twitter

4 Comments

dmark84  on September 7th, 2010

I’m running CakePHP 1.3.3, MAMP 1.9.1, and Snow Leopard 10.6.4, and my CakePHP Console was looking for the MySQL socket in:

/var/mysql/mysql.sock

After I created a symbolic link to my MAMP MySQL socket there, it worked fine.

Chuck Burgess  on September 7th, 2010

dmark84, thanks for the update. Another solution is always welcome.

chris.brinker  on October 2nd, 2010

Another solution to this issue is to specify the port explicitly within the cakephp config/database.php file:

class DATABASE_CONFIG {
var $default = array(
‘driver’ => ‘mysql’,
… cut …
‘port’ => ‘/Applications/MAMP/tmp/mysql/mysql.sock’,
};
}

Mac+XAMPP?bake??????????  on February 26th, 2011

[...] CakePHP Shell Not Seeing MySQL with MAMP Pro MAC If you enjoyed this article, please consider sharing it!   [...]

Leave a Comment

You must be to post a comment.