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 ( 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:


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


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. 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.


    socket = /tmp/mysql.sock

  2. herringtown says:

    Thanks! That saved me some heartache…. cheers.

  3. Snowcore says:

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

  4. emon says:


  5. erkin says:

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

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

  7. kenorb says:

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

  8. Duy says:

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

  9. That did it! Thank you very much

  10. Helpful post. Thanks!

  11. 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.

  12. 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? :)

  13. Heberti Almeida says:

    Thank you!

  14. 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.