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

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

    On Mac OSX using Mamp Pro, what solved the problem for me was going to the MySQL tab on the UI and checking the option Allow network access to MySQL

    Don't forget to click Save to update the settings

    0 讨论(0)
  • 2020-12-15 07:51

    This is a bit stupid but I arrived on this post googling the same error, so maybe this can help someone.

    In case you have this Connection refused Error double check that your database is up and running, in my case I simply forgot to power on MAMP...

    0 讨论(0)
  • 2020-12-15 07:51

    After seeing the answers and playing around with this myself I figured out the problem:

    The default installation of LAMPP, MAMPP has the following in the my.cnf file:

    skip-networking

    This means that mysql will not listen on TCP/IP so you can tell doctrine to try any port in the 64K and it won't do any good until you comment out the directive above and get mysql to listen to TCP/IP ports.

    Please ensure you restart LAMPP, MAMPP or reload mysql after commenting out the skip-networking directive.

    0 讨论(0)
  • 2020-12-15 07:56

    I had the same problem using MAMP because the default port is not 3306 but 8889.

    You can find that information in the MAMP starting web page.

    My parameters

    parameters:
        database_driver: pdo_mysql
        database_host: 127.0.0.1
        database_port: '8889'
        database_name: symfony_blog
        database_user: root
        database_password: root
        mailer_transport: smtp
        mailer_host: 127.0.0.1
        mailer_user: null
        mailer_password: null
        locale: en
        secret: 7f03537e81f981683bc773b9ec7113ab5861adec
        database_path: null
    
    0 讨论(0)
  • 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
    0 讨论(0)
  • 2020-12-15 07:58

    i had the same issue and fixed it changing

    database_host: 127.0.0.1
    

    to

    database_host: localhost
    

    in parameters.yml

    hopefully this helps

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