Despite the hate that is going on right now at CakeFest. MAMP is fine for local development and can work with CakePHP just fine.

If you are seeing this when you try to bake however:

Warning Error: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in [/Users/mojowill/Sites/cakephp/lib/Cake/Model/Datasource/Database/Mysql.php, line 149]

Error: Database connection "SQLSTATE[HY000] [2002] No such file or directory" is missing, or could not be created.
#0 /Users/mojowill/Sites/cakephp/lib/Cake/Model/Datasource/DboSource.php(260): Mysql->connect()
#1 /Users/mojowill/Sites/cakephp/lib/Cake/Model/ConnectionManager.php(101): DboSource->__construct(Array)
#2 /Users/mojowill/Sites/cakephp/lib/Cake/Console/Command/Task/ModelTask.php(908): ConnectionManager::getDataSource('default')
#3 /Users/mojowill/Sites/cakephp/lib/Cake/Console/Command/Task/ModelTask.php(845): ModelTask->getAllTables(NULL)
#4 /Users/mojowill/Sites/cakephp/lib/Cake/Console/Command/Task/ModelTask.php(934): ModelTask->listAll(NULL)
#5 /Users/mojowill/Sites/cakephp/lib/Cake/Console/Command/Task/ModelTask.php(204): ModelTask->getName()
#6 /Users/mojowill/Sites/cakephp/lib/Cake/Console/Command/Task/ModelTask.php(92): ModelTask->_interactive()
#7 /Users/mojowill/Sites/cakephp/lib/Cake/Console/Shell.php(390): ModelTask->execute()
#8 /Users/mojowill/Sites/cakephp/lib/Cake/Console/Shell.php(387): Shell->runCommand('execute', Array)
#9 /Users/mojowill/Sites/cakephp/lib/Cake/Console/ShellDispatcher.php(201): Shell->runCommand('model', Array)
#10 /Users/mojowill/Sites/cakephp/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
#11 /Users/mojowill/Sites/cakephp/lib/Cake/Console/cake.php(43): ShellDispatcher::run(Array)
#12 {main}

You need a little help!

First thing you need to do is create the folder location it is looking for:

sudo mkdir /var/mysql

Secondly you need to create a symbolic link from /var/mysql/mysql.sock to your MAMP mysql.sock:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

Now try running your cake bake model command again….

I know good isn’t it!

6 thoughts on “Quick Tip: CakePHP Baking and MAMP

  • Does not work 🙁


    • 2 Things:

      1) This is a fairly old article so perhaps it doesn’t work anymore?2) A little more information on your error might actually give me or anyone else the opportunity to offer some help. It does not work really doesn’t tell anyone anything!


  • Any ideas on how to make this work with MAMP PRO?


    • I was using MAMP Pro so you should be fine, however in all honesty I haven’t used MAMP probably since this article was written!


  • it works for like 10 min. Afterwards it breaks again! Really weird, didn’t changed a line of code.


  • Thanks a lot, works for me


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Mojowill Avatar

Who the Hell am I?

I'm Will, a full time web developer, geek and musician. I develop using PHP and MySQL and spend most of my time working with WordPress or CakePHP. When I'm not buried in code I'm gaming, cooking or writing and recording music in my studio. I like sci-fi, pancakes and coffee and am totally prepared for the zombie apocalypse...

Stalk me on these other sites...

Why not be super creepy and check me out on all these other sites, I think they call it social media?

%d bloggers like this: