Veltar
Veltar

Reputation: 741

How do I set up a database for Symfony2 using Doctrine?

I'm following the Symfony book and arrived at the chapter on dealing with the database. I have a few questions, and can't seem to find an answer.

I'm just following the parameters.yml file that I have looks like this (auto-generated)

parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: null
    database_name: myproject
    database_user: root
    database_password: null
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: en
    secret: ThisTokenIsNotSoSecretChangeIt
    debug_toolbar: true
    debug_redirects: false
    use_assetic_controller: true

Then I head over to the terminal and enter:

php app/console doctrine:database:create

I receive the following error:

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

I have a few questions:

Upvotes: 0

Views: 3731

Answers (2)

Veltar
Veltar

Reputation: 741

After a long search I found it. It had something to do with the mysql.default_socket as pointed out in the comments.

MAMP showed me the socket was

':/Applications/MAMP/tmp/mysql/mysql.sock'

After doing some more searching, I found that the socket can be set in config.yml, here:

doctrine:
  dbal:
    driver:   "%database_driver%"
    [...]
    unix_socket: "/Applications/MAMP/tmp/mysql/mysql.sock"
    [...]

If the unix_socket line is not there, just add it. Then tried to execute the same command in Terminal, which gave this result:

Created database for connection named `myproject`

And the database was really created.

Upvotes: 3

Andreas P.
Andreas P.

Reputation: 118

Symfony doesn't install mysql I assume you are working in a lamp stack.

If I remember well it happened to me once and I changed database_host: 127.0.0.1 to localhost and it worked well since.

Upvotes: 1

Related Questions