(“public_html” or “www”).- Go into “wp-content” and rename the “plugins” folder. For example- plugins_.- Go back to your site and see if the error is still there.- If not, then it’s been caused by some plugin. - Go back to FTP, rename the folder back to “plugins”. - Now change the folder names of the individual plugins, one by one.- Keep coming back to your site to see when the error gets triggered or disappears. - Once you’ve narrowed it down to one specific plugin, you have found the troublemaker.

In case 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.

#4 Restore The Default WordPress Files

If the issue is still not resolved, then you can restore the default WordPress files. Database connection error can occur due to corruption in core WordPress files. May be there was an attack by a hacker, malicious plugin or you modified some files by accident.

Whatever the reason it might be, you can still restore native WordPress files by downloading a clean version of WordPress from WordPress.org and copy it over the one you have right now.

Steps to restore the default WordPress files are given below:-

  • Go to <a href=“https://wordpress.org/download/\” rel=“noreferrer noopener” target=“_blank”>https://wordpress.org/download/- Download the latest package to your desktop.- Unpack it and delete the “wp-content” folder- Connect your site via FTP - Visit the main WordPress root- Upload your new WordPress files and overwrite all the previous ones. - After it is done, check your website to see if the error has been resolved or not.

If this also fails, then you must contact your web hosting provider immediately for help.

#5 Solutions that worked for others

Sometimes the connection error doesn’t go away even after repairing the database and valid login credentials. In these type of cases, the issue can be with the site url.

To update the same, you can run a SQL query by going to phpMyAdmin:-

UPDATE wp_options SET option_value=’YOUR_SITE_URL’

WHERE option_name=’siteurl’

Replace YOUR_SITE_URL with your actual website url example. For example:- <a href=“https://serverguy.com/\“>https://serverguy.com/

How To Avoid This Error In Future?

As discussed above there are many ways to fix database connection error in WordPress. One of the most common reasons behind this error is wrong login credentials in the wp-config.php file.

Therefore, you can begin by checking these details and then proceed to the next steps.

No one wants their website to go down. Here are some measures that you can take to prevent this type of error in the future:-

**Quality Web Hosting:- **It is crucial for every WordPress site owner that they go for those hosting providers who have optimized their platforms for WordPress. Managed WordPress hosting can prevent your site from going down as they ensure 100% uptime and 24*7 support.

**Having Proper Backups:- **One can never have sufficient back ups. Therefore, you must ensure that you always have a working back up that you can restore in case of emergency.

**Enabling Cache:- **You must enable WordPress cache and choose its duration according to how often you update your website. Your hosting partner can also help you in taking the right decision.

We hope this guide helps you in tackling this error. If you are still struggling with this issue or want to give us feedback, then you can reach out to us. You can also leave a comment below and we will get back to you.