"Error establishing a database connection" in local WordPress environment after Yosemite upgrade

Upgrading to Yosemite changed my local development Apache/PHP/MySQL environment and thus broke my local WordPress sites. I was able to get things in order by tweaking my local Apache config back to what it was using the httpd.conf~previous file as a reference.

Once I got Apache working as expected, I started getting the "Error establishing a database connection" error though nothing had changed in my wp-config.php file.

I had read a solution about capitalizing the "localhost" DB_HOST constant to "Localhost" in wp-config, but that didn't work.

It's a homebrew install of MySQL and I can access the "localhost" db server with command line and SequelPro app.

Answers


I changed the DB_HOST to the internal IP "127.0.0.1" and that fixed it.


OSX Yosemite (and maybe other newer versions of OSX as well) looks in the wrong location for the mysql.sock file, which is why upgrading to Yosemite broke your local sites. Creating a symlink to the correct location will solve the problem:

sudo mkdir /var/mysql
sudo chmod 755 /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

The reason the missing symlink is a problem for WordPress specifically is because in your wp-config.php file, define('DB_HOST', 'localhost'); will not work. An alternative workaround is to change this value in your wp-config file to define('DB_HOST', '127.0.0.1');.


Need Your Help

Cannot resolve PC machine from Mac browsers

macos web-services networking dns bonjour

I'm currently writing some POC's where I need to consume a web service from my Mac. I write the web service on my PC and now I need the Mac to be able to consume it for debugging purposes. When wor...