Symfony 2 SQLSTATE[HY000] [2002] Connection refused Error

前端 未结 12 2394
耶瑟儿~
耶瑟儿~ 2020-12-15 07:31

I get an error like database operations using Symfony2.

SQLSTATE[HY000] [2002] Connection refused

parameters.yml

parameters         


        
12条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 07:39

    Had this issue "SQLSTATE[HY000] [2002] No such file or directory" on symfony 3.2.9 on deployment

    I fixed it by changing the database_host value from "localhost" to my server IP on my parameters.yml file

    but I had this another error message when trying to run commandline by SSH:

    [Doctrine\DBAL\Exception\ConnectionException]
      An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused
    

    I finaly fix it by adding these 2 lines on my config.yml file in Doctrine configuration section :

    unix_socket: /var/lib/mysql/mysql.sock
    server_version: '5.5'
    

    all my final doctrine configuration is like this:

    doctrine:
        dbal:
            driver: pdo_mysql
            host: '%database_host%'
            port: '%database_port%'
            dbname: '%database_name%'
            user: '%database_user%'
            password: '%database_password%'
            unix_socket: /var/lib/mysql/mysql.sock
            server_version: '5.5'
            charset: UTF8
    

    hopefully this helps

提交回复
热议问题