I get an error like database operations using Symfony2.
SQLSTATE[HY000] [2002] Connection refused
parameters.yml
parameters
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
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...
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.
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
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:
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