Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

后端 未结 17 2466
长发绾君心
长发绾君心 2020-11-22 08:27

I\'m trying to connect to my MySQL DB with the Terminal on my Apple (With PHP).

Yesterday it worked fine, and now I suddenly get the error in the title.

The

17条回答
  •  青春惊慌失措
    2020-11-22 08:51

    The mySQL client by default attempts to connect through a local file called a socket instead of connecting to the loopback address (127.0.0.1) for localhost.

    The default location of this socket file, at least on OSX, is /tmp/mysql.sock.

    QUICK, LESS ELEGANT SOLUTION

    Create a symlink to fool the OS into finding the correct socket.

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

    PROPER SOLUTION

    Change the socket path defined in the startMysql.sh file in /Applications/MAMP/bin.

提交回复
热议问题