An “Error establishing a database connection” is a fatal WordPress error that makes your website inaccessible to other visitors. It normally occurs when you have a weak or no connection with your backed database. As a beginner, many webmasters struggle to fix this error as they think that their website got defective. If this error occurs on your website, it can be incorrect data information, an irresponsible database server, or a corrupt database of your WordPress site.
A database is a software that organizes, edits, retrieves, and data on your website. A CMS system, like WordPress access these database files to store the content of your website.
Check Database Credentials
The most common type of fix is to manually check your WordPress database credentials. If you have recently shifted your website to a new host, chances are your credentials are not set for the new site. You can check this by going to your WordPress database “wp-config.php” file.
Here, check the information for the database name, username, host, and password if it’s correct or not. If anything’s wrong, contact your housing provider.
Check Database Host Information
If you’re confident that your database username, the password is correct, there’s a possibility that your database host information is incorrect. Mostly WordPress uses localhost, but sometimes the managed hosting can make separate files. For this, you have to contact your hosting provider for host information.
Repair WordPress Database
WordPress provides you a separate option to repair your database if any error occurs. Some of the webpage showcase this error as well on your screen. To repair your database, you first have to enable the restricted section of your database. For this go to your hosting cPanel and access the “wp-config.php” file.
Add this line in the file: “define(‘WP_ALLOW_REPAIR’, true);“, add the line without braces. Save the file and go to the URL: httpS://www.yoursite.com/wp-admin/maint/repair.php
Here enter the name of your site and change the protocol if required. A new window will open in which a repair and optimize button will appear. Once you’re done with optimizing and repairing your WordPress database, make sure you remove the code from the wp-config.php file.
Database Server is down
Sometimes there’s no problem from our side but from the server-side. These are common types of problems that can occur if you manage a WordPress website. On the back-end, MySQL server may have been temporarily unavailable that cause this error. This could happen due to heavy traffic on either your site connection or server.
Your site will get slow and the user won’t access it. So the best thing to do here is to contact your hosting provider and let them fix the problem. The solution doesn’t require a lot of time and your site will be up and running in no time. Change the hosting or upgrade to a more secure version that provides bandwidth.
Ask for Help
If none of these methods worked for you, contact the back-end developer or hosting provider for help. A good WordPress hosting company will always help you related to your WordPress site. We hope that this article will help you a lot in solving the problem.