There is no connection to the "Mysql" database and no mysql.sock

I tried to create model code from cake command line tool. But this is a problem.

Warning Error: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in [/Users/test/Google_WWW/project_name/lib/Cake/Model/Datasource/Database/Mysql.php, line 177] Error: Database connection "Mysql" is missing, or could not be created. (although it showing that mysql database is connected at localhost in cakephp directory) 

I am using MAMP.

I searched a lot and found some solutions. For example, this is CakePHP: There is no such file or directory (attempt to connect via unix: ///var/mysql/mysql.sock)

or I can also make a mysql.sock symbolic link.

 /Applications/MAMP/tmp/mysql/mysql.sock (not present in directory) 

But before you do anything, the problem in the mysql.sock file is not in this directory. I tried reinstalling MAMP, but not mysql.sock.

Please help me solve this problem? Can I create my own mysql.sock .. file?

Edit: My db config

 public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'login' => 'root', 'password' => 'root', 'database' => 'db_name', 'prefix' => '' ); 
+7
mysql cakephp mamp
source share
6 answers

MAMP is weird when it comes to mysql. Most likely, you need to create a symbolic link so that it knows where to find it. Something like:

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

+8
source share

After searching and trying a lot, I finally managed to solve my problem. Chuck Burgess answer above may solve the problem, but my script was a bit different that I could not see the mysql.sock file at:

  /Applications/MAMP/tmp/mysql/mysql.sock 

I thought my mysql.sock was missing, but it was actually there and hidden (THAT STRANGE! I WANT TO DRINK THIS using CLI AND SAW THAT). I use MAC and files starting with '.' usually HIDDEN, but I don’t know why mysql.sock was hidden, so I did this in my database configuration file. I added 1 parameter (unix_socket) and my problem was resolved.

  'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock' 
+3
source share

In my case, it was because I was calling the wrong version of PHP. That is, I used /usr/bin/php , which when MAMP Pro php is set to /Applications/MAMP/bin/php/php5.3.29/bin/php

+1
source share

In my case, the problem occurs immediately after turning off the power. So I fixed it by deleting the file /Applications/MAMP/tmp/mysql/mysql.pid and restarting MAMP.

+1
source share

I struggled with this all weekend and finally decided. It turns out that php.ini points to a nonexistent "extension directory". Create a phpinfo () file and look at the value of this field: extensions_dir

I noticed that in the installed mamp php folder there is a no-debug-non-zts-20131226 folder, which is different from the value specified in phpinfo (). I cloned this folder and changed the name to phpinfo (). Perhaps you can modify the php.ini file, but I did not want to.

I see that you solved your problem, but everything was different for me, so I am sending this answer to help future googlers look for a similar problem.

Hope this helps.

0
source share

Using MAMP, create a symbolic link in the / var / mysql / folder:

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

0
source share

All Articles