Error Establishing a Database Connection

I hadn’t started up my virtual test server since changing the network configuration to get port forwarding to work properly. Today when I tried it out, I got the dreaded “Error Establishing a Database Connection” message on all my local WordPress sites.

Even the mysql client couldn’t connect to the database, and of course neither could phpmyadmin. The database server was running and I had even restarted it multiple times to make sure. Removing it and installing it again didn’t help either.

I finally found the problem in the mysql config file in /etc/mysql/my.cnf. The bind-address setting was set to the old fixed IP address I had been using. I’m not sure why it hadn’t broken before when I first changed from a fixed IP to the Virtualbox NAT. I changed it back to ‘localhost’, restarted mysql server, and all my sites started working again.

EDIT: I realised from’s statistics page that there are quite some visitors landing here by searching for the title. The information above is probably not what you’re looking for.

If you’re getting this error on your self hosted install, check the settings in the wp-config.php file. If you’re unsure what the values should be, ask your hosts. Every host configures their servers in their own way. Some have the database on the same machine, so the DB_SERVER setting is ‘localhost’. Others might put it on a dedicated database server with its own hostname. Also make sure that your hosting plan lets you use a database. Some of the cheapest ones may not.

If you’re still stuck, post a question in the Installation or How-to and Troubleshooting sections of the forum.


One thought on “Error Establishing a Database Connection”

  1. hi…my name’s braima from guine bissau and i have seem problem whit connection to my database but i work in local whitout hosting the problem that when i lauch my local siteweb wordpress it send me back error message database error

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s