If your WordPress site shows the message “Error Establishing Database Connection”, it usually indicates one of the following issues:
-
The database has crashed or become corrupted
-
Incorrect database login credentials in the WordPress configuration file (
wp-config.php) -
Corrupted or damaged WordPress database tables
This guide will walk you through each possible cause and show how to fix it.
Step 1: Repair the WordPress Database
Database corruption can happen due to failed updates, plugin errors, or server issues. A corrupted database often triggers the database connection error. WordPress provides a built-in repair feature to fix this.
How to Enable Database Repair
-
Open your wp-config.php file in a text editor.
-
Add the following line to any blank line in the file:
define('WP_ALLOW_REPAIR', true);
-
Save the file and close it.
-
In your browser, visit:
http://www.yourdomain.com/wp-admin/maint/repair.php
-
You’ll see the Repair Database page. Click the Repair Database button to start the process.
-
Once the repair finishes, remove the line you added to wp-config.php to avoid a potential security risk.
After repairing, check your site to see if the error is resolved.
Step 2: Verify Database Login Credentials
If you recently moved your site to a new server or hosting provider, the database credentials may need updating. These are stored in the wp-config.php file.
How to Check Credentials
-
Open wp-config.php in a text editor.
-
Locate the following lines:
/** The name of the database for WordPress */
define('DB_NAME', 'database_name');
/** MySQL database username */
define('DB_USER', 'database_username');
/** MySQL database password */
define('DB_PASSWORD', 'database_password');
-
Ensure that the values for
DB_NAME,DB_USER, andDB_PASSWORDmatch your hosting account’s database credentials. -
If any details are incorrect, update them, save the file, and reload your website.
Step 3: Restore from Backup (if needed)
If the above steps don’t resolve the issue, you may need to restore your database from a backup. Many hosting providers, including Prabhu Host, offer daily offsite backups for WordPress sites, which makes restoration simple and quick.
Summary
-
Use WordPress’s built-in repair feature to fix corrupted tables.
-
Double-check your database credentials in wp-config.php.
-
Restore from backup if repairs and credential updates don’t work.
Following these steps will usually resolve the “Error Establishing Database Connection” issue and get your WordPress site back online quickly.