In WordPress “Error establishing a database connection”, is a very common error when you try to access your website. In most case this issue is, one of the following:
1) The database has been corrupted. The database stores all the important data of your website including posts, comments, user accounts information’s, etc.
2) As we all know the database details are configured in the wp-config.php file. If we configure wrong details of the database, we will get this error.
3) If the mysql service is stopped, you will get this error.
In most of this case, we can’t access both website and the WordPress Dashboard. Some case we can access the WordPress dashboard when we get the error “Error establishing a database” while accessing the website. If we got wp-admin access and main domain is still loading with “Error establishing a database connection” that means “One or more database tables are unavailable”. The database may need to be repaired to resolve this issue. In this case, we can repair the database through wp-admin.
1) First, take current database backup.
2) To enable repair option
Edit wp-config.php file
Add below line in the wp-config.php file
define(‘WP_ALLOW_REPAIR’, true);
3) Go to the following page to repair database https://www.yourdomain.com/wp-admin/maint/repair.php
4) From there click “Repair and Optimize Database” button.
Make sure to disable the repair option once the database has been repaired.
If the issue still persists after repairing the database, you need to restore the database from an available backup.
To troubleshoot the error “Error establishing a database connection”, refer following KB How To Fix “Error Establishing Database Connection” In WordPress
If you need any further assistance please contact our support department.