Symfony2 CLI does not connect to MySQL while browser works fine.

So i had an issue that i am still somewhat unsure of the cause, though i suspect the culprit was an upgrade to a newer version of MAMP.

So when using the Symfony2 project in the browser, everything works fine, however on the CLI i get the following:

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

[ErrorException]
Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in …htdocs/Symfony/vendor/doctrine-dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php line 36

So i thought it was pretty odd that the CLI would not connect when the browser did just fine. I tried adding this to my parameters.ini:

Though this seems to have made no difference what so ever. It seems SF2 CLI would ignore the sock file location and was only interested in the sock file located in the /private/var/mysql directory. So the solution is to make a symlink to the sock file thus resolving the issue. Do the following to resolve it:

This should resolve the issue.

12 thoughts on Symfony2 CLI does not connect to MySQL while browser works fine.

  1. I had the same errors some time ago, (and too search a bit to resolve it !) But do you still use MAMP ? I switched too MacPorts because I found it had annoying limitations (at least in the free version) No intl ext… see you. 🙂

  2. @COil I have not had a lot of issues really except for the one in this blog post. Thing is, its more likely my own fault than it is MAMPs because i tried to revert to an older installation after the MAMP upgrade moved PHP to a version no longer supporting references in the way i needed.

    Apart form that, not ran into any other limitations yet so i am still using MAMP as i quite like it.

    What features are MAMP missing that you require?

  3. Howdy! I could have sworn I’ve been to this website before but after reading through some of the post I realized it’s new to me. Anyhow, I’m certainly delighted I found it and I’ll be book-marking and checking back often!

  4. My guess is that Mr Robinson was paid by ShapiroFAG or one of his chronies to smear UM’s name since its getting close to the start of the season.

  5. Incredibly thankful. Give me a shout if you happen to pass by stockholm and would like a beer.

  6. Hello,

    I solved it with this command (first you need to cd in the symfony project directory) :

    /Applications/MAMP/bin/php/php5.3.6/bin/php app/console doctrine:schema:update –dump-sql

     

  7. I have the same problem, but the database is in other server and the socket is not the default.

    Could you help me?

    Do you have any idea?

  8. Thanks for the hint! I had to change the “database_host” to localhost in additional to get this work.

  9. hi , I have the same problem, but i still couldn’t find a solution .
    i’m a beginner using symfony2,
    i’m trying to create a database “php app/console doctrine:database:create” ,and i get this errors ;
    [Doctrine\DBAL\Exception\ConnectionException]
    An exception occured in driver: SQLSTATE[HY000] [2002] No such file or dire
    ctory

    [Doctrine\DBAL\Driver\PDOException]
    SQLSTATE[HY000] [2002] No such file or directory

    [PDOException]
    SQLSTATE[HY000] [2002] No such file or directory

    i tried all the suggested solutions , but it didn’t work .
    here is my parameters.yml :
    parameters:
    database_host: localhost
    database_port: 3306
    database_name: mydatabase
    database_user: mydbBase
    database_password: testDataBase
    mailer_transport: smtp
    mailer_host: localhost
    mailer_user: null
    mailer_password: null

    Thanks for helping

  10. sudo mkdir /var/mysql
    sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
    sudo chown _mysql /var/mysql/mysql.sock
    sudo chmod 777 /var/mysql/mysql.sock

Leave a Reply