Archive
Old post. Originally published 30 August 2012 on the WordPress version of this site.
Preserved here for the search engines and the curious. Old me had opinions.
Quick Tip: CakePHP Baking and MAMP
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!
Filed under Developer. No comments, on purpose.