What are search engines and SEO? The continuous episode of SEO

What is a search engine? Search engine is a technology that lets you...

How to fix the “Error Establishing a Database Connection” in WordPress

Why do you get this error? What Causes This Error? The ‘Error establishing a...

How To Set Up a Custom Domain in Blogger – The Right Way!

Blogger is a free Google publication platform primarily used for creating blogs. Blogs are usually hosted by Google on the blogspot.com...

Leave a reply

Please enter your comment!
Please enter your name here

Why do you get this error? What Causes This Error?

The ‘Error establishing a database connection’ issue can be caused by incorrect database information in your WordPress settings, corrupt database, or an irresponsive database server.

This form of error can be caused by several factors

  • invalid login credentials,
  • change in port,
  • file permission,
  • corrupt database,
  • changes in wp-config and
  • .htaccess.

5 Easy Fixes for Quick Error Establishing a Database Connection in WordPress:

  1. Check If Your Plugin or Theme Files Haven’t Been Corrupted.
  2. Check Your WordPress Database Credentials.
  3. Get In Touch With Your Web Host Provider.
  4. Repair a corrupt database with WordPress’ built-in database repair mode: define(‘WP_ALLOW_REPAIR’, true);
  5. Restore The Default WordPress Files

Check If Your Plugin or Theme Files Haven’t Been Corrupted

Your WordPress files can get damaged due to a few misfortunes.

For instance, you might have updated a plugin or a theme, and the whole thing collapsed? Maybe you’ve hooked the site up to an external service? You may have hand-edited some of the files?

If any of the bell rings above, you’re probably going to have your guilty one. If you haven’t already done any of that, skip this step.

First login to your cPanel > public_html (or your website if you have multiple website in the same hosting)

Second: Go into “wp-content” and rename the “plugins” folder to something else

Third: Go back to your site and see if the error is still there.

If not, you now know that it’s been caused by some plugin. Go back and rename the folder back to “plugins”. Go in it, and change the folder names of the individual plugins, one by one. The easiest way to do this is to add an underscore at the end: “_”

Keep coming back to your site to see when the error gets triggered or vanishes. Once you’ve narrowed it down to one specific plugin, you have found the troublemaker. Either delete it or go online to see if the solution has been documented.

  • If the error is still there even after renaming the “plugins” folder, go through the exact same process with the “themes” folder.
  • If that doesn’t help, rename both folders back to “plugins” and “themes”. The error is caused by something else.

Check Your WordPress Database Credentials

Your WordPress database credentials are stored in the wp-config.php file. It is the WordPress configuration file that contains important WordPress settings including database information.

You need to make sure that the information for the database name, username, password, and database host is correct.

You can confirm this information from your WordPress hosting account dashboard. Simply log in to your hosting account and click on MySQL databases under the database section.

This will take you to the database management page in your hosting dashboad. From here, you can find out your database name and the username.

Below that you will find the database users and links to change the user password.

Once you have confirmed your database name, username, and password, you can change that information in your wp-config.php file if needed.

After that, try visiting your website again to see if the database connection error has gone.

If you can still see the error, then this means that something else is wrong. Continue reading for more troubleshooting steps.

Get In Touch With Your Web Host Provider

If you are confident that your database name, username, and password information is correct, then you may want to make sure that you are using the correct database host information.

In most cases, if you tell them what sort of error you’re having, they will either let you know what the cause is exactly, or they will even fix it for you.

Most importantly, they will let you know if your database is alright and whether or not there’s any suspicious activity on the server.

Repair WordPress Database

If you get a different error on the wp-admin, for example, something like “One or more database tables are not available. The database may need to be repaired, “so you need to repair your database.

You can do this by adding the following line to your wp-config.php file. Make sure you add it just before ‘That’s all, quit editing! Happy blogging line wp-config.php.

define('WP_ALLOW_REPAIR', true);

Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php

Note: the user does not need to be logged in to access the database repair page. Once you are done repairing and optimizing your database, make sure to remove this code from your wp-config.php.

Restore The Default WordPress Files

As we mentioned earlier, core WordPress files can be corrupted for a variety of reasons. Maybe there’s been a hacking attempt on your web, maybe you changed some files by mistake, maybe a rogue plugin made a shift.

Whatever it might be, you can always restore the default WordPress native files. The best way to do that is to download a clean WordPress version from WordPress.org and copy it to the one you’ve got right now.

Go here and add the latest kit to your desktop. Unpack. Unpack. Browse the unpacked directory and remove the “wp-content” folder.

Next, link to your site via FTP, go to the main WordPress root, upload your latest WordPress files. Overwrite all of the previous files.

When you have completed the upload, return to your site and see the effect.

This is the last resort to any kind of repair. If this doesn’t help, you won’t have a choice but to go back to your web host support line, tell them everything you’ve done, and ask for help. At this point, you have essentially exhausted everything you could do to fix the issue yourself, and it’s the host’s turn to solve it. After all, you pay your hosting bills, aren’t you?

How To Avoid This Error In the Future?

While you do not have a 100% unsure way to secure your site from any data base link failures, there are 2 key elements that should be at least 90% protected in your assurance puzzle:

Hosting quality. Act with hosts only who have optimized WordPress platforms. In this way, you can still depend on know-how and swift assistance. Also, several common issues with WordPress can be avoided.

Have backups. Install a simple backup plugin like UpdraftPlus (it works automatically) and you should always have a working WordPress backup that you can restore in case everything else fails.

Hope this guide helps! And as always, feel free to comment if you still having the issue.

- A word from our sposor -

How to fix the “Error Establishing a Database Connection” in WordPress