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:

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

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.

8 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?

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">