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

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


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

enter image description here


There is a parameter unix_socket you can use within your config.yml.

See full configuration example:

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   %database_driver%
                dbname:   %database_name%
                user:     %database_user%
                host:     %database_host%
                password: %database_password%
                unix_socket: /tmp/mysql.sock