Database connection “Mysql” is missing and mysql.sock is missing

前端 未结 7 1584
轻奢々
轻奢々 2021-01-12 13:46

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 (try         


        
相关标签:
7条回答
  • 2021-01-12 13:53

    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

    0 讨论(0)
  • 2021-01-12 13:56

    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

    0 讨论(0)
  • 2021-01-12 13:56

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

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

    0 讨论(0)
  • 2021-01-12 14:05

    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.

    0 讨论(0)
  • 2021-01-12 14:10

    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.

    0 讨论(0)
  • 2021-01-12 14:14

    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'
    
    0 讨论(0)
提交回复
热议问题