Here’s how to fix the error establishing a database connection in WordPress.
1. WP-Config.php is probably the single most important file in entire WordPress installation. First, check all the wp-config.php file is correct and same without any changed.
2. Next, check login page whether get errors for the same “Error Establishing Database Connection”. It may be getting a ton of traffic especially if you are using a shared server. Immediately contact hosting provider.
3. If WordPress site shown “One or more database tables are unavailable. The database may need to be repaired” then you will need to repair your database.
You can do this by adding the following line in your wp-config.php file:
4. Once you have done that, you can see the settings by visiting this page: https://www.yoursite.com/wp-admin/maint/repair.php
5. Next, the screen will appear with two repair options. Just click Repair Database.
The WordPress site will recover once completed repair.
6. Go to wp-config.php file and remove “define(‘WP_ALLOW_REPAIR’, true)”, and then Save the file.