PDOException SQLSTATE[HY000] [2002] No such file or directory

后端 未结 30 2580
南方客
南方客 2020-11-22 03:23

I believe that I\'ve successfully deployed my (very basic) site to fortrabbit, but as soon as I connect to SSH to run some commands (such as php artisan migrate

30条回答
  •  长发绾君心
    2020-11-22 03:36

    This is because PDO treats "localhost" host specially:

    Note: Unix only: When the host name is set to "localhost", then the connection to the server is made thru a domain socket. If PDO_MYSQL is compiled against libmysqlclient then the location of the socket file is at libmysqlclient's compiled in location. If PDO_MYSQL is compiled against mysqlnd a default socket can be set thru the pdo_mysql.default_socket setting.

    (from http://php.net/manual/en/ref.pdo-mysql.connection.php)

    Changing localhost to 127.0.0.1 will "force" the use of TCP.

    Note: mysqli_connect is working fine with localhost.

提交回复
热议问题