I get an error like database operations using Symfony2.
SQLSTATE[HY000] [2002] Connection refused
parameters.yml
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: '8889'
database_name: symfony
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: tr
secret: ef9b4381fe75208f060b7c786951242bebcfb3c2
database_path: /private/var/mysql/mysql.sock
And console:
Kemal-Karakass-MacBook-Pro:~ kemalkarakas$ locate mysql.sock
/private/var/mysql/mysql.sock
How do I resolve the error?
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...
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
There is a parameter unix_socket you can use within your config.yml.
See full configuration example:
If anyone is still stuck on this issue when using a virtual environment, I found if you are attempting to run database commands on the host machine and running into the
"connection refused"
error, try ssh-ing into your guest machine and running the commands directly so the path to mysql.sock is correct.(I guess it makes sense that the relative path needs to be on the virtual guest machine, not the host machine).
Configuring symfony2/doctrine to connect to MySQL using host:port
doctrine.dbal.path: %database_path%
inapp/config/config.yml
database_path
fromapp/config/parameters.yml
app/config/parameters.yml
single quotes or put all in double quotes.Afterwards your configuration should look like this:
Parameters
Configuration
i had the same issue and fixed it changing
to
in parameters.yml
hopefully this helps