How to Fix the Error Establishing a Database Connection in WordPress

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
5 (100%) 1 vote

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”

errordbconnection

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
1
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 http://www.yoursite.com/wp-admin/maint/repair.php to start repair your database.

wprepairdb

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  How to Solve 403 forbidden NGINX

 

 

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,

1
2
3
4
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.

1
define('DB_HOST', '127.0.0.1:8889');

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 Downgrade WordPress to an Earlier Version

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

(Visited 55 times, 1 visits today)

Admin

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! https://wpcolt.com/advertise/

commodo elit. in elementum Donec sem, fringilla

Pin It on Pinterest

Do you find this interesting?

Share it with your friends!