CakePHP MAMP MySQL FAQ: I'm using the "cake bake" command in a CakePHP application I'm developing using MAMP, and I get a MySQL socket connection error, specifically:
Warning: mysql_connect(): [2002] Connection refused (trying to connect via unix:///var/mysql/mysql.sock) in /Applications/MAMP/htdocs/myapp/cake/libs/model/datasources/dbo/dbo_mysql.php on line 552 Warning: mysql_connect(): Connection refused in /Applications/MAMP/htdocs/myapp/cake/libs/model/datasources/dbo/dbo_mysql.php on line 552 Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /Applications/MAMP/htdocs/myapp/cake/libs/model/datasources/dbo/dbo_mysql.php on line 558 Warning: mysql_get_server_info() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/myapp/cake/libs/model/datasources/dbo/dbo_mysql.php on line 566 Warning: mysql_query() expects parameter 2 to be resource, boolean given in /Applications/MAMP/htdocs/myapp/cake/libs/model/datasources/dbo/dbo_mysql.php on line 600 Your database does not have any tables.
While this "cake bake" MAMP MySQL socket connection error message looks pretty nasty, it's easily resolved. You just need to make a change in your CakePHP application's database configuration file.
To fix this "cake bake" MAMP MySQL socket connection error, just edit your CakePHP application's database configuration file:
$ vi app/config/database.php
and change your entry that looks something like this:
var $default = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'username', 'password' => 'password', 'database' => 'databasename', 'prefix' => '', );
to this, specifically telling CakePHP which MySQL socket to use, i.e., the MAMP MySQL socket:
var $default = array( 'driver' => 'mysql', 'persistent' => false, 'host' => 'localhost', 'port' => '/Applications/MAMP/tmp/mysql/mysql.sock', 'login' => 'username', 'password' => 'password', 'database' => 'databasename', 'prefix' => '', );
The MySQL port line I added (shown in bold) to this CakePHP database configuration file solves this cake bake MAMP MySQL problem. Once you make that change, your "cake bake" commands should work just fine with your MAMP MySQL database, as it now knows how to find the MAMP MySQL socket.
I hope this CakePHP MySQL socket connection error tip has been helpful.
Cake bake or cake back?
In the title, you put cake 'bake'.
cake bake it is
Oops, thanks. It is actually "cake bake", and I corrected that in the article. You can issue a bunch of "cake" commands, like:
and
etc. Thanks for catching the error.
Interesting. What a weird
Interesting. What a weird framework. I use Drupal for everything.
CakePHP
CakePHP is basically the PHP version of Ruby on Rails ... as PHP frameworks go, I like it more than the others I've tried.
'port' => 8889, // mysql
'port' => 8889, // mysql port
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', // path to mysql.sock
For CakePHP 2.3.2
Post new comment