This is Part 2 of our series of fixing Error Establishing a Database Connection.
Part is is listed here: https://www.sktthemes.org/wordpress/error-establishing-a-database-connection/
If you have just set up your website and you come across the dreaded “error establishing a database connection”, chances are that would set you running for the hills.
And if it so happens that you are not that tech savvy, then it is more likely than not that you would be pressing that panic button all the way through.
The fact remains that if you do work with WordPress, then you are bound to come across this issue more often than not, and it is alarming enough for even advanced developers to come across this message.
This usually occurs due to one primary reason; WordPress stores all the files and the content on your website in a database and each time you want to access a specific web page, WordPress sends a request to your web host and to its server and checks the tables for the required data and then displays the same.
And if for some reason it is not able to access the WordPress posts table, then the dreaded error message makes an appearance.
The good news is that there are a few steps you can take on your own to resolve this and the steps listed below should help you to do just that.
This error often occurs due to corrupted files, database being overloaded, corrupted database, incorrect credentials and the list goes on.
Just check out some of the ways by which you can resolve this issue at the earliest and keep in mind that the longer your website is down, you are going to lose out on prospective leads and customers alike.
Just review the steps listed below, and follow the directions as listed. The steps listed here are fairly easy and you should be able to resolve the issue soon.
1. Do a complete backup:
The first thing that you need to do before you try out the steps listed below is to do a complete back up. And while there are several plugins that can help you do the same, the issue once this error arises is that you would not be able to access the front or the back end.
If that’s the case, then you need to use your web host’s management software to do the complete backup. You can also use your cPanel for the same. Once you have backed up your data, you are all set to proceed ahead.
2. Wrong credentials:
Usually, if you have just migrated to a new web host and this issue appears then the likely culprit is a case of wrong credentials.
Your WordPress site requires four different items in order to access your database and all of these are required to be entered correctly. They are your database host, username, password and database used.
Download the wp-conifg file and make the required changes to username and password. Now, use your FTP client to upload the file, reload your website and it should work.
3. Corrupted files:
In case, the first option does not work, then the error could be as a result of corrupted files in which case, you need to download a fresh copy with all core files from WordPress.com. Now, unzip the downloaded file and delete the wp-config and wp-content files from the same.
This is to ensure that you do not use these to accidentally replace the live ones on your server. Now, open up your FTP client and upload the remaining files to your WordPress root folder.
By doing so, you should be able to overwrite all the corrupted files and your website issues should be resolved.
4. Corrupted database:
In case of a corrupted database, in which case either your front end or your backend would work but not both. In that case, what you need to do is to head over to your FTP account, download your wp-config.php file and add in this particular code.
This is to activate a tool that WordPress already provides you with, which can help to resolve corrupted database issues.
define( 'WP_ALLOW_REPAIR', true );
Now, upload the file to the root directory via FTP and you should soon be able to access your repair site. It will provide you with the option to repair your database, as well as the option of optimizing the same.
Choose the former and once your database issue is sorted out, head back to wp-config file and remove the above line of code. This is to enhance the security of your website.
5. Overloading, malfunctioning issue:
If your website server is overloaded or is malfunctioning, then you need to contact your webhost, apprise them of the problem and ask them for help.
Your web host would definitely look into it right away and sort out the issue, in which case your website issue should get resolved within short time frame.
Keep in mind that the issue could also be as a result of increased traffic and that your server is getting overwhelmed which is why you should move to a better hosting than shared, at the earliest.
6. Try managed WordPress hosting:
A good idea to resolve the current issue and avoid more of the same in the future would be to move to a managed WordPress hosting service.
Granted that you may not get the same freedom to install all the plugins you want but on the plus side, issues such as database errors never enter the picture.
If the above steps have not resolved the issue, then you need to contact your web host right away, apprise them of the various steps you have undertaken and ask them to resolve it.
If they aren’t able to resolve it, then you need to approach the professionals and get a developer to take a look at the same.
These are some of the steps that you need to undertake to resolve the error establishing a database connection issues. Just remember that this issue crops up often and you do not have to panic.
It can be resolved easily so just try out the steps listed below and you should be able to resolve it at the earliest, and get your website up and running in no time at all.