Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create database connection for Doctrine2 in Symfony2 with MAMP (Connection refused)

I'm in the process of learning Symfony2 for a project that me and some friends are taking on, and am taking a tutorial where you make a blog in Symfony2: http://tutorial.symblog.co.uk/docs/doctrine-2-the-blog-model.html

Problem

I can't seem to get Doctrine2 to work. I give the following instruction to the Terminal:

php app/console doctrine:database:create

And get the following error message:

Could not create database for connection named symfony SQLSTATE[HY000] [2002] Connection refused

System info

I have a mac that runs Mountain lion and I use MAMP.

What I have done

I went to the config page (http://localhost/NameOfProject/web/config.php) and went to the place where you configure your database. There I put in the path, port, user, password, etc from the MAMP start page.

What I have tried

A blog I came across suggested to create a symbolic link to the the MAMP mysql socket with the following command:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock

This did not make the error go away for me.

Some of my files in symfony (if they are relevant)

From app/config/config.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: en
    secret: 0408312e2b9861c0c86dbb7488aceec4296054ec
    database_path: /Applications/MAMP/tmp/mysql/mysql.sock

From app/config/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: en
    secret: 0408312e2b9861c0c86dbb7488aceec4296054ec
    database_path: /Applications/MAMP/tmp/mysql/mysql.sock

The tutorial talks updating the database_* options in the parameters file located at app/config/parameters.ini. However, I don't have a parameters.ini file located in this folder! Only parameters.yml.

Edit: Solution:

I was using the wrong port number for MySql. When I used 3306 it worked.

like image 902
Tor Avatar asked Mar 04 '13 00:03

Tor


1 Answers

I was using the wrong port number for MySql. When I used 3306, the standard mysql port, it worked. (Thank you jperovic)

like image 113
Tor Avatar answered Oct 17 '22 04:10

Tor