Symfony2 + Doctrine + MAMP: Could not create database for connection named … SQLSTATE[HY000] [2002] No such file or directory


Recently was working through a Symfony2 tutorial and ran into an issue. Tried performing a create database command and ran into an issue.

Create Database Command


php app/console doctrine:database:create

The Error


Could not create database for connection named nameofthedatabase
SQLSTATE[HY000] [2002] No such file or directory

The Fix

Using MAMP, I had to create a symbolic link to the the MAMP myslq socket.


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

Rerun the command and all should be good!

What is the mysql.sock?

“The mysql.sock is the socket that mysqld creates for programs to connect to.”

7 thoughts on “Symfony2 + Doctrine + MAMP: Could not create database for connection named … SQLSTATE[HY000] [2002] No such file or directory

  1. Owen Jeremiah

    I think you’re using Mac OSX Lion.
    If you are, you should change the value /var/mysql/mysql.sock to /tmp/mysql.sock in php.ini, since Apple moved it from their default location.

    Reply
  2. Mike Rouse

    If you’re on Mac OSX Mountain Lion I found that I needed to do the following:

    “cd /var”

    “sudo mkdir mysql”

    “cd mysql”

    “ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock”

    Reply
  3. Roy

    I’ve tried adding a symlink as per Mike’s suggestion, and have also tried changing php.ini like Owen said, and neither of those work for me. Does anyone have an idea why else this would happen?

    Reply

Leave a reply to Roy Cancel reply