Fix “Error establishing database connection” in WordPress


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.

define(‘DB_NAME’, ‘your-database-name’);
define(‘DB_USER’, ‘your-database-username’);
define(‘DB_PASSWORD’, ‘your-database-password’);
define(‘DB_HOST’, ‘your-localhost’);

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:

define(‘WP_ALLOW_REPAIR’, true)

4. Once you have done that, you can see the settings by visiting this page: http://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.