WordPress problems: Cannot Connect To Database

It seems to be that there’s a whole lot of people that are getting this error message when they are trying to install or move their WordPress site. Even though this problem is common and there’s a very simple solution, people seem to always have more trouble with it then it’s worth.

So, what’s the problem?

The problem is easy to diagnose. You try to install or load your wonderful WordPress website, and all you see is a big black message saying “Error establishing database connection”.

What this means is that the database connection credentials that you’ve got set up in your wp-config.php file are not correct. Some people don’t realise that you have to change them yourself, and some people rush to much and either put in the wrong values, or don’t put in all of the values that they need to.

The lines that you need to set up are:

define('DB_NAME', 'my_db_name');
define('DB_USER', 'db_username');
define('DB_PASSWORD', 'db_password');
define('DB_HOST', 'localhost');

This is all pretty straight-forward, but here’s what each setting is:

  1. DB_NAME – The name of the database.
  2. DB_USER – The username for the database user. Remember that this is not your website or control panel login.
  3. DB_PASSWORD – The password for the database user.
  4. DB_HOST – This is the host name of the MySQL server. Most times this will be either ‘localhost’ or ‘’ if the MySQL server is on the same physical server as your website, but it may be a different domain URL or IP address if the database is hosted on a different server.

You can get these settings either by setting up your own database on your web server, or your hosting company will give these to you when you request a new database from them.

So, what’s the solution?

The solution is simple: use the correct settings.

Having said that, it can be easier to say that then to do it. There’s a few common mistakes that people make, and these are:

  1. Incorrect spelling. The amount of times that I’ve seen this error occur because someone has got one single letter wrong can’t be counted. Double-check every setting that you have entered. The best way is to copy-and-paste the values so that you know that they are correct.
  2. Incorrect host name. Even tough 99% of setups will work with ‘localhost’ there’s always some that won’t. If this happens you can try using the local IP address of the server as ‘’ and if this doesn’t work you’ll need to contact your hosting company to check what the correct host name for the database server is.
  3. Using your website or control panel username and password. Remember that under normal circumstances these will not be the same. If they are, that’s a very big security issue, so I’d look at changing the details for the database user to something a lot more secure.
  4. Forgetting to set the values. Yes, I’ve seen this (and done it myself). When things get hectic, sometimes we can forget, and this extends to forgetting to actually set the values that you need in the file. You’ll feel stupid when you do this, but don’t worry – you are not alone!

So there you have it. That is really all there is to fixing this problem. Remember that if you do experience issues like this, your hosting company and your developer are going to be some of your best friends, and they can help you with these problems. Don’t be afraid to ask, because we’ve heard this many many times before and we are there to help you.

Leave a Reply

Your email address will not be published. Required fields are marked *