Magento Ignoring Host in local.xml – Unix Socket Connection Issue

databaseerrormagento-1.8MySQL

I have a magento site that works just fine in production. However, when I create an identical clone of the site in a 'dev' subdomain on the same hosting site (for maintenance work) I get the dreaded: "SQLSTATE[HY000] [2002] No such file or directory" error.

My investigation has revealed that indicates that Zend PDO is attempting to connect to a local database using a Unix socket but none exists. This makes sense since MySQL isn't running on localhost, but on a separate server.

What doesn't make sense is why Magento / Zend are attempting to connect to MySQL via unix socket when there is a remote hostname specified in my local.xml !

And, since it will be asked…

  • yes, the credentials and host are correct and connectivity is fine
    • several other webapps in the same subdomain work just fine
    • this is a connection error, not an authentication error
  • yes, I cleared the cache

Best Answer

Through instrumenting my site with debug logging, I discovered Magento was somehow picking up the wrong database configuration information (trying to use localhost).

I had the correct information in local.xml. But Magento was somehow loading connection information from a different .xml file.

I have backups of local.xml for my various debug/test environments(localhost.local.xml, development.local.xml, and live.local.xml) in app/etc. This is so I can easily copy the correct config to local.xml for the specific environment.

Apparently magento is loading these other .xml files and it is overriding the values in local.xml. Isn't magento only supposed to load global.xml and local.xml ?

My solution was to remove all of the extra backup .xml files from the app/etc directory. After doing that my dev site worked fine!

UPDATE: More information on why this is occuring can be found in this answer.

Related Topic