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.”
I have followed up as you guide but nothing resolved! Thanks for sharing at all!
No luck? You were unable to create the symbolic link? Any additional details on your issue?
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.
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”
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?
Thanks a lot for trying to help out, Mike. I haven’t gotten rid of the error though. Not after trying the advice in the comments either.
Here’s a description of my problem in stackoverflow: http://stackoverflow.com/questions/15192587/cannot-create-database-connection-for-doctrine2-in-symfony2-with-mamp-connectio
Did you eventually solve your problem, Roy?
I did, Tor! What got it to work for me was explicitly adding the unix_socket directive under ‘doctrine’ to config.yml:
unix_socket: /Applications/MAMP/tmp/mysql/mysql.sock
I found this solution here:
http://www.iamseree.com/application-development/doctrine-create-database-error-no-such-file-or-directory
(Souley’s comment)