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

前端 未结 12 2373
耶瑟儿~
耶瑟儿~ 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:56

    Today on a fresh installation of Symfony3 I had the same error:

    SQLSTATE[HY000] [2002] Permission denied

    Installation specs:

    • CentOS Linux 7.2.1511
    • Symfony 3.1.2
    • MariaDB 5.5.47
    • PHP 7.0.8

    An earlier answer by izus did resolve the problem on my server. He suggests to change the parameter database_host from 127.0.0.1 to localhost in the Symfony configuration file app/config/parameters.yml

    The real origin of the problem was not inside Symfony configuration, but authorization inside the database server. I've created the database and authorization for this database by executing the following SQL queries:

    CREATE DATABASE user CHARACTER SET utf8 COLLATE utf8_bin;
    GRANT ALL PRIVILEGES ON database.* TO user@localhost IDENTIFIED BY 'password';

    This query implies only the host 'localhost' is authorized. This doesn't match '127.0.0.1' exactly. The database server rejects the incomming connection, and Symfony is throwing an exception and showing this error message.

    Possible solutions to this specific situation:

    1. Change the database_host parameter
    2. Change the authorization inside the database server

提交回复
热议问题