WordPress Guides How to Fix 'Error Establishing a Database Connection'
“Error establishing a database connection” means WordPress loaded but can’t reach its database, so no page can be built. It’s one of the most common WordPress errors — and usually fixable in a few minutes.
What causes it
- Wrong database credentials in
wp-config.php(name, user, password or host). - A corrupted database after a crash or interrupted update.
- Exhausted resources — the server ran out of memory/processes so MySQL couldn’t respond.
- A changed database password that
wp-config.phpwasn’t updated to match.
How to fix it
1. Check wp-config.php against cPanel (most common)
In cPanel File Manager, open wp-config.php in your site root and find:
define('DB_NAME', 'yourdb');
define('DB_USER', 'yourdbuser');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');
Compare each value with cPanel → MySQL Databases:
- DB_NAME and DB_USER must match exactly (including the account prefix, e.g.
user_wp). - DB_HOST is almost always
localhoston shared hosting. - If the password is uncertain, reset the database user’s password in MySQL Databases and paste the new one into
wp-config.php.
See create a MySQL database in cPanel for where these live.
2. Repair a corrupted database
If credentials are correct, the database may be corrupted. Add this line to wp-config.php:
define('WP_ALLOW_REPAIR', true);
Then visit yourdomain.com/wp-admin/maint/repair.php and click Repair Database. Remove the line afterward — it’s a security risk left in place.
3. Check the database in phpMyAdmin
Open phpMyAdmin from cPanel and confirm the database exists and has tables (wp_posts, wp_options, etc.). An empty database means a restore is needed — see back up and restore with JetBackup and import/export a MySQL database.
4. Rule out resource exhaustion
If the error comes and goes under traffic, the server may be hitting limits so MySQL can’t respond. Check Resource Usage — see understand your resource usage and the memory limit guide.
Still stuck?
Your error logs confirm whether it’s an authentication failure or the database being unreachable, and common WordPress errors covers related issues. Our support team can check the database server for you.
Every Web Hosting and WordPress Hosting plan at Genhost includes MySQL, phpMyAdmin and daily backups, so you can fix or restore a database yourself.
Frequently asked questions
What causes 'Error establishing a database connection'?
WordPress can't reach its database. The usual causes are wrong database credentials in wp-config.php, a corrupted database, or the server being out of resources so MySQL can't respond. Checking wp-config against cPanel is the first step.
Where are my database details in WordPress?
In wp-config.php in your site root — the DB_NAME, DB_USER, DB_PASSWORD and DB_HOST lines. They must exactly match the database and user shown in cPanel's MySQL Databases.
Can I fix a corrupted WordPress database myself?
Yes — add define('WP_ALLOW_REPAIR', true); to wp-config.php, then visit yourdomain.com/wp-admin/maint/repair.php and run the repair. Remove the line afterward for security.