Database connection "Mysql" is missing and mysql.sock is missing
Asked Answered
P

7

7

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' => ''
);
Parson answered 11/10, 2013 at 14:22 Comment(4)
can you please post your database configuration parameters?Lovieloving
edited my question, one thing I must say that database is connected without any issues. But for creating model via cakephp cli, it uses mysql.sock that's not present in mamp folder I mentioned.Parson
what if you try 127.0.0.1 instead of localhost?Lovieloving
No, still same issue.. Thanks for the reply though !Parson
S
11

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

Seanseana answered 12/10, 2013 at 0:8 Comment(5)
Thanks for the reply. I did create a symbolic link but my problem wasn't solved.Parson
To 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.sockWoodwind
the 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 fineCherokee
The blog link above does not work. Also this symlink solution is aimed at MAMP, not MAMP PROConveyor
bravo, your solution really work. i stuck in this problem for almost 2 weeksLampblack
P
4

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'
Parson answered 15/10, 2013 at 12:15 Comment(1)
same here its hidden and can see it via cli. but when i add the unix_socket still i dont get connected.Cherokee
C
1

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

Conveyor answered 1/5, 2015 at 14:34 Comment(1)
Man how do you do thisHamlett
Z
0

I've been struggling with this the whole weekend and finally solved it. Turns out that the php.ini is pointing to a non-existing "extensions dir". Create a phpinfo() file and look at the value of this field: extensions_dir

I noticed that in the mamp php installed folder there is a no-debug-non-zts-20131226 folder, which is different from the value shown in the phpinfo(). What I did was to clone this folder and changed the name to the value of the phpinfo(). Probably you could modify the php.ini file but I didn't want to.

I see that you solved your problem but mine was different so I'm posting this answer to help future googlers looking for a similar problem.

Hope this helps.

Zalea answered 2/11, 2014 at 18:44 Comment(0)
H
0

In my case the problem appear just after a power outage. So I fixed it by deleting the /Applications/MAMP/tmp/mysql/mysql.pid file and restarting MAMP.

Hurtless answered 17/10, 2016 at 23:26 Comment(1)
this broke my mamp :-(Arching
E
0

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

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

Extract answered 25/10, 2016 at 14:30 Comment(0)
S
0

Same problem here, but managed to resolve it connecting to IP:Port, not socket.

'host' => '127.0.0.1', //use 172.0.0.1 instead of localhost
'port' => '8889', //default MAMP MySQL devel port, default production port is 3306

and forget about socket connection.

Strapped answered 22/8, 2020 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.