Magento Install: Mysql Error – SQLSTATE[HY000] [2002] No such file or directory

I recently changed up the configuration of my Mac (running 10.6.4) and I was installing a fresh copy of Magento (1.4.1.1) when I ran into the following error when I got to the database credentials: SQLSTATE[HY000] [2002] No such file or directory.

I did some Googling around and came across someone that seemed to have a similar issue, though not with Magento. So I figured I’d give it a shot. Well, it worked. The unfortunate part is that, being not all too familiar with how all this configuration stuff works, I don’t know why it works (if you know why, please let me know).

The Solution

Open up your php.ini file (mine was in /etc/). Look for the following line:

pdo_mysql.default_socket=/var/mysql/mysql.sock

If that line exists for you, try changing it to:

pdo_mysql.default_socket=/tmp/mysql.sock

Restart apache after saving, and that’s all I had to do. One thing to keep in mind though is that I am using the stock php (with 10.6), and I’m using mysql installed with homebrew.

This entry was posted in Magento, MySQL, PHP. Bookmark the permalink.

14 Responses to Magento Install: Mysql Error – SQLSTATE[HY000] [2002] No such file or directory

  1. Steve Cichosz says:

    The reason this works is because the “mysql.sock” file is used to document the open socket being used to communicate with the database and the initial entry to the php.ini file was forcing a creation attempt in a directory that did not exist. The alternate way to fix the problem would be to have created the initially referenced “/var/mysql” directory and ensure the permissions were correct to allow the web services to write there.

  2. Heberti Almeida says:

    Thank you!

  3. vanyatka says:

    I got the same issue, trying to connect to remote host. Obviously, no any mysql.sock business is involved.

    What do I do? :)

  4. These problems can be quite annoying. I love it when there are so many resources out there to find solutions to our problems. It is funny how sometimes that it is as easy as changing one little line to fix your problems.

  5. That did it! Thank you very much

  6. Duy says:

    Well, this post saved me from wasting hours of fixing this problem. Thanks!!

  7. kenorb says:

    MAMP users:
    cd /var/mysql && sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock .

  8. Thanks so much! This saved me when trying to install ModX.

  9. erkin says:

    thank you so much that i didnt have to fool around PDO : )

  10. emon says:

    thanks!

  11. Snowcore says:

    Your solution is the best among others on the internet. Thank you very much!

  12. herringtown says:

    Thanks! That saved me some heartache…. cheers.

  13. In my case i also need to change socket configuration for mysql

    We have to edit some settings in my.cnf for MySQL, so we go back to vi. In Terminal, type:

    sudo vi /usr/local/zend/mysql/data/my.cnf

    Use the down arrow to scroll down to where it says:

    socket = /usr/local/zend/mysql/tmp/mysql.sock

    With your blinker over the “s” on “socket”, type “#” to comment out that line

    Use the down arrow to go to the next line.

    Type:

    socket = /tmp/mysql.sock

Leave a Reply

Your email address will not be published. Required fields are marked *

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