PHP MySQL – Fix PDO Exception Error on Index

indexingMySQLPHP

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in lib/Zend/Db/Adapter/Pdo/Abstract.php:129

I get the following error on my local machine. (Mac OSX running Apache/MySQL natively) I can run Magento from the frontend, but I can't reindex at the command.

Best Answer

Just a guess, but it sounds like

  1. Your command line php executable uses a different php.ini file than the web server

  2. The php.ini file your command line version uses has a different, and invalid, value set for the mysql.default_socket ini setting

When you specify a MySQL server host as localhost, you're telling the system to use this socket file to connect to the database server. Check the value when using your local web-server, and make sure that same value is set for the command line program's ini file.

You might also have some luck changing the server to 127.0.0.1 from localhost. (When the system sees an IP address, it knows not to connect via the socket file, but instead to connect via TCP)