How to Fix the Error Establishing a Database Connection in WordPress

Spread the love

How to Fix the Error Establishing a Database Connection

If you getting this error on your website. You are at the right place. Today we are going to discuss step by step “How to Fix the Error Establishing a Database Connection in WordPress”


This error message is evident that your site can’t interface with the database. However, fathoming this mistake can be dubious for tenderfoots.

Generally, this happens when a client has entered or changed their database credentials (database host, database username, and database password) mistakenly. Infrequently your database server could be lethargic, or your database may have ruined.

* NOTE – Before you do any changes, please make sure backup your database.

Step 1 : Check wp-admin if getting the error as well
If you’re getting this message “One or more database tables are unavailable. The database may need to be repaired”, instead of  ” Error establishing a database connection” on the wp-admin. You need to repair your database.
Just add one line code to config.php file
define('WP_ALLOW_REPAIR', true);

Add the code above just before That’s all, stop editing! Happy blogging’ line wp-config.php.

Once you have done the step, go to to start repair your database.


After you access the links above, click on “Repair and Optimize Database”. Once completed, please go back to the config.php file remove the code that added earlier. If you have the problem to running repair and unable to fix the problem, please continue next step.

READ  Too Many Redirect Wordpress Website- Fix Solution



Step 2: Checking wp-config

wp-config file is the most important file in WordPress website. If the root password or database password has changed, you need to update in this file as well. To ensure the website is running well. Please check your wp-config.php file, all the information should be the same as what you had created  in the database,

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

*Please take note that not all Host are “localhost”. But for the popular hosting such as Hostgator, BlueHost, Site5, it’s localhost. Some of the experts suggest us to replace localhost with your IP. It might be work, after changed to IP instead of localhost.

define('DB_HOST', '');

The IP will be different for all website hosting, please get the IP from your Hosting company.

Step 3: Check your Web Host (MySQL Server)

Some of you might notice that you getting this error after your site gets huge traffic which your host server cannot cope. This usually happens to the shared hosting website. Your website will get slower, end up even output error. So for this condition, the best is to contact your hosting company either through livechat or phone. Ask them to check your MySQL server is responsive. If there is MySQL issue, your host will help you to fix it.

The solutions above might or might not works for you. Please use this at your own risk, please make sure you have done your full backup before trying it out.

READ  How to Translate WordPress Themes That Come Without Languages Files

Please comment below, how you solve your problem? To let more people know about this. Thanks!

(Visited 273 times, 1 visits today)


I write about Multilingual WordPress, SEO, Website Performance, Plugins and Themes. Also, I like answering WordPress question on Quora. I like to research and review for Wordpress Plugin! Look for me if you have any Wordpress product!

id vulputate, amet, id, non felis venenatis justo eleifend facilisis

Pin It on Pinterest

Do you find this interesting?

Share it with your friends!