Magento PDO exception error while running command line on Mac OSX

Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[HY000] [2002] No such file or directory’
I was getting this error when i tried to run magento script from command line on Mac OSX.

If you have the same problem like me, find out the location of your mysql.sock. You can do that as follows

mysql -u root -p
show variables like '%socket%'

Now go to your local.xml and change your host to

/tmp/mysql.sock

And enjoy.

Updated on Jan 5, 2014: This error is due to you installed XCode with its bundled PHP. Another solution is to add your own PHP executable into your environment variable $PATH, to do so, you can edit your ~/.bash_profile to add/replace with following line (while /usr/local/zend/bin should be replaced by where your php executable located):

PATH=/usr/local/zend/bin:/usr/local/zend/mysql/bin:$PATH
Posted in PHP
One comment on “Magento PDO exception error while running command line on Mac OSX
  1. Arif says:

    Mountain Lion with MAMP solution:

    sudo ln -f /Applications/MAMP/bin/php/php5.4.4/bin/php /usr/bin/php

    Source: http://stackoverflow.com/questions/4399269/how-to-set-default-port-on-mysql-for-mac

Leave a Reply

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

*