PDO connection error when using symfony and MAMP

前端 未结 4 2132
耶瑟儿~
耶瑟儿~ 2021-02-14 05:18

Getting an PDO error when trying to do php symfony doctrine:insert-sql
The error I get:

Warning: PDO::__construct(): [2002] Connection refused         


        
4条回答
  •  自闭症患者
    2021-02-14 06:04

    MAMP by default doesn't allow TCP connections. You can either turn it on or use sockets.

    Changing your dsn as @Tom suggests should fix your issues. Weird as it is but using localhost instead of 127.0.0.1 makes that mysql connects through sockets.

    http://dev.mysql.com/doc/refman/5.0/en/connecting.html :

    On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the --protocol=TCP option.

提交回复
热议问题