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

kemal picture kemal · Oct 28, 2013 · Viewed 78.2k times · Source

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?

Answer

izus picture izus · Nov 3, 2014

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