5

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.

3
  • 2
    Are you sure you need to specify database_path? Also 'Connection refused' suggests that host was found and nobody is listening on that particular port. Does your mysql listen on port 8889? Standard mysql port is 3306... Commented Mar 4, 2013 at 9:58
  • Unless I misunderstood something, jperovic, it seems your answer was given as a comment, and thus I cannot officially "accept" your answer. But thanks a lot anyway!! :) Commented Mar 4, 2013 at 15:28
  • Ah, yeah, that was just a suggestion. I will write an answer now in order for you to successfully close the question ;) Commented Mar 4, 2013 at 16:33

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

For those who still can't resolve this problem, try to enable Allow network access to MySQL in MAMP settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.