PDO connection error when using symfony and MAMP

前端 未结 4 2094
耶瑟儿~
耶瑟儿~ 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 05:59

    Looks right. Here would be the exact equivalent from a working databases.yml I'm using, in case it's of any use:

    dsn: 'mysql:host=localhost;dbname=jobeet'
    
    0 讨论(0)
  • 2021-02-14 06:01

    I had the same error when attempting to build my tables in Symfony and using MAMP. I fixed the issue by changing my dsn line, in the databases.yml file, to the following:

    dsn: 'mysql:host=localhost;dbname=jobeet;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock'
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-14 06:06

    MAMP PRO 2.x
    I was able to solve this and many similar issues by simply unchecking "Allow local access only" in the MySQL prefs on the MAMP control panel.

    enter image description here

    MAMP PRO 3.x
    As stated by Kendrick: enter image description here

    0 讨论(0)
提交回复
热议问题