简体   繁体   中英

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

我将DB_HOST更改为内部IP“ 127.0.0.1”,并对其进行了修复。

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'); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM