We learn Fix the WordPress Error Establishing Database Connection.

Whenever you work with WordPress you have seen “WordPress Error Establishing Database Connection”

error at least ones. Few days before I also face this problem when I login to my website this error occurs I am so upset because I can’t login to my website due to this error.

You May Also Like:

Note: Before you make any database changes, make sure you have sufficient backups. Now we will show you how to fix the WordPress Error Establishing Database Connection.

Why do you get this error?

While doing the research to find possible causes. I found some reasons of this error so first of all you check down these things

  • Are you sure you have the correct username and password?
  • Are you sure that you have typed the correct hostname?
  • Are you sure that the database server is running?

In short this error occurs due to some login problem and due to your server is down.

Does the problem occur for /wp-admin/ as well?

First of all make sure that back-end of the website (wp-admin) also show different error from front-end of the site something like this “error about database missing some files” etc. the database of the website need to repair.

Just add simple code in wp-config.php file

define('WP_ALLOW_REPAIR', true);

After this adding this code you can repair database

WordPress Error Establishing Database Connection

If this repair did not fix the problem, or you face the same problem then you follow next steps.

Checking the WP-Config file

WP-Config.php is the most important file of WordPress. This file is used to connect your database. If you changed your root password, or the database user password, then you will need to change this file as well. First thing you should always check is if everything in your wp-config.php file is the same.

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');

Remember your DB_Host value might not always be localhost. Depending on the host, it will be different. For popular hosts like HostGator, BlueHost, Site5, it is localhost. Some times to fix this problem when we replace localhost with IP. For example on MAMP, the DB_Host value when changed to the IP may seem to work.

define('DB_HOST', '');

If every thing is correct and still you face the same problem then something is wrong with your server.

Check your Web Host (MySQL Server)

When your website gets so many users or traffic your host server cannot handle the load specially when you are shared hosting. Your site will slow down. Test other sites on the same server to see if they are having the issue. If they are also getting the same error, then most definitely there is something wrong with your MySQL server. If you do not have any other site on this same hosting account simply go to your cPanel and try to access phpMyAdmin and connect the database.

Create a new file called testconnection.php and paste the following code in it:

$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
echo 'Connected successfully';

If you cannot connect to the database by going to phpMyAdmin, then you know it is something with your server. It does not necessarily means that your MySQL server is down. It could mean that your user does not have sufficient permission.

If MySQL server is also running then problem is out of your range then this problem solve by your web server call to  like HostGator, BlueHost, Site5.


About The Author

Related Posts

Leave a Reply

Your email address will not be published.