Database connection "Mysql" is missing and mysql.sock is missing
Solution 1
MAMP is strange when it comes to mysql. Chances are you need to set up a symbolic link so it knows where to find it. Something like:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
Solution 2
After searching and trying a lot of things I finally managed to solve my problem. The answer Chuck Burgess given above could solve the problem, but my scenario was little different that I wasn't able to see mysql.sock file at:
/Applications/MAMP/tmp/mysql/mysql.sock
I thought my mysql.sock was missing but actually it was there and hidden (THAT's STRANGE! I WENT TO THAT FOLDER using CLI AND SAW THAT). I'm using MAC and files starting with '.' are usually HIDDEN but don't know why mysql.sock was hidden so what I did is in my database configuration file I added 1 parameter (unix_socket) and my problem was solved.
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock'
Solution 3
In my case it was because I was calling the wrong version of PHP. I.e. I was using /usr/bin/php
which when MAMP Pro's php is /Applications/MAMP/bin/php/php5.3.29/bin/php
ihaider
Updated on June 05, 2022Comments
-
ihaider almost 2 years
I was trying to generate model code from cake command line tool. But got this issue.
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's showing that mysql database is connected at localhost in cakephp directory)
I'm using MAMP.
I searched a lot and found some solutions. For instance,this CakePHP: No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)
or I can also make a symbolic link of mysql.sock.
/Applications/MAMP/tmp/mysql/mysql.sock (not present in directory)
But before i do anything, the problem is mysql.sock file isn't present in this directory. I have tried re-installing the MAMP but still no 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' => '' );
-
ihaider over 10 yearsThanks for the reply. I did create a symbolic link but my problem wasn't solved.
-
Seb33300 about 10 yearsTo use it with php-cli, after creating the symbolic link, edit your php.ini:
pdo_mysql.default_socket= /tmp/mysql.sock
,mysql.default_socket = /tmp/mysql.sock
,mysqli.default_socket = /tmp/mysql.sock
-
Harsha M V almost 10 yearsthe file is not created at all in my case. can you please tell me how to get mamp to generate the file? but phpmyadmin works perfectly fine
-
Harsha M V almost 10 yearssame here its hidden and can see it via cli. but when i add the unix_socket still i dont get connected.
-
geoidesic over 9 yearsThe blog link above does not work. Also this symlink solution is aimed at MAMP, not MAMP PRO
-
Monclee about 8 yearsMan how do you do this
-
rcpfuchs about 7 yearsthis broke my mamp :-(
-
Sruit A.Suk over 2 yearsbravo, your solution really work. i stuck in this problem for almost 2 weeks