As I’m working with Symfony 2 with Doctrine as an ORM and using MySQL as a database.
I found this error when trying to create a database using the command “php app/console doctrine:database:create”.
I got “No such file or directory” error message.
After researched, I’ve found that my MAMP is missing one thing…
When Doctrine is trying to create a new database, it is finding a ‘/var/mysql/mysql.sock’ which never exists in my system after MAMP installed.
So, the solution is to create a symbolic link to where the actual mysql.sock stay with this command…
“cd /var”
“sudo mkdir mysql”
“cd mysql”
“ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock”
Then try to run “php app/console doctrine:database:create” again.
It will works!
UPDATED:
If you are using Zend Server, you probably found the same error, just do the same but create a symbolic link to “/usr/local/zend/mysql/tmp/mysql.sock” instead of MAMP’s.


For me not. I don’t know what i am doing wrong, may be you have an idea.
localhost:Symfony nico$ ./app/console doctrine:database:create
Could not create database for connection named symfony
SQLSTATE[HY000] [2002] No such file or directory
symbolic links:
localhost:mysql nico$ ls -la /var/mysql/
total 16
drwxr-xr-x 4 root wheel 136 6 Jul 23:48 .
drwxr-xr-x 30 root wheel 1020 6 Jul 23:44 ..
lrwxr-xr-x 1 root wheel 38 6 Jul 23:48 mysql.pid -> /Applications/MAMP/tmp/mysql/mysql.pid
lrwxr-xr-x 1 root wheel 39 6 Jul 23:45 mysql.sock -> /Applications/MAMP/tmp/mysql/mysql.sock
solution found.
./app/config/config.yml # or config_dev.yml
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
unix_socket: /var/mysql/mysql.sock
Thank Nico!, this was really pissing me off.
but for me the unix socket was this on MAMP install:
unix_socket: /Applications/MAMP/tmp/mysql/mysql.sock
I use EasyPHP my error is ‘could not create database for connection named symfony could not find driver’ Do you have any solution plz help me !
Thanks Nico, it worked for me
Thank You very much ! Just for people : You should to return on your repository ” /MAMP/httpdocs/Symfony ” before use the” $ php app/console doctrine:database:create “