Error Establishing A Database Connection

When you try to access your website and all you can see is the message "Error Establishing Database Connection," this means that there is a problem with the connection to your database. The following are possible reasons and solutions.

Database server is down

If you are very sure that you did not edit wp-config.php file and you did not edit your database username and password from your web hosting panel. It could be your database server is down and your web server is unable to connect to it. You will need to contact your web hosting company to verify this.

Check your database on your web hosting panel

You may have accidentally deleted your database from your web hosting panel. In this case, there is nothing you can do but to re-create a database and start WordPress all over again. If you have changed your database username or password, you will have to edit your wp-config.php to reflect the changes.

Check your wp-config.php

You may have accidentally edited the database settings in your wp-config,php or you may have edited your database settings from your web hosting panel. You will have to check your wp-config.php to ensure that your database settings are correctly defined. 

Your settings should look similar as the following, except the values. You should replace them with information that you get from your database setup in your web hosting panel.

	// ** MySQL settings - You can get this info from your web host ** //<br>
	/** The name of the database for WordPress */<br>
	define('DB_NAME', 'customizr-pro');<br>
	
	/** MySQL database username */<br>
	define('DB_USER', 'root');<br>
	
	/** MySQL database password */<br>
	define('DB_PASSWORD', 'root');<br>
	
	/** MySQL hostname */<br>
	define('DB_HOST', 'localhost');<br>

Your website may be compromised

If you have checked wp-config.php for errors, and confirmed that your database server is working properly. It is possible that your site has been hacked. You can scan your site with Sucuri SiteCheck to eliminate this possibility. If your site is hacked, you should engage a security professional to clean up your site. If you would like to do it yourself, you may refer to My Site was Hacked documentation.

External Resources

  1. Common WordPress Errors
  2. Why is WordPress unable to connect to my database during install ?