I get an error like database operations using Symfony2.
SQLSTATE[HY000] [2002] Connection refused
parameters.yml
parameters
Today on a fresh installation of Symfony3 I had the same error:
SQLSTATE[HY000] [2002] Permission denied
Installation specs:
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: