Fix: WordPress Error Establishing a Database Connection

Estimated reading: 2 minutes

The “Error Establishing a Database Connection” screen means WordPress can’t connect to its MySQL database. Here are all the common causes and fixes.

Cause 1: Wrong Credentials in wp-config.php

The credentials in wp-config.php must match exactly what’s set in cPanel. Log in to cPanel → File Manager → open your site’s root folder → edit wp-config.php and verify:

define( 'DB_NAME',     'your_database_name' );
define( 'DB_USER',     'your_database_user' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST',     'localhost' );

To confirm the correct values, go to cPanel → MySQL Databases and check the database name, username, and that the user has ALL PRIVILEGES on the database. If the password is wrong, reset it there and update wp-config.php to match.

Cause 2: Database User Not Assigned to the Database

In cPanel → MySQL Databases, scroll down to Add User To Database. Make sure your database user is assigned and has ALL PRIVILEGES. This step is easy to miss when creating a new database.

Cause 3: Corrupted Database Tables

If credentials are correct but the error persists, the database tables may be corrupted. Add this line to wp-config.php (above the /* That's all, stop editing! */ line):

define( 'WP_ALLOW_REPAIR', true );

Then visit https://yourdomain.com/wp-admin/maint/repair.php and click Repair Database. Remove that line from wp-config.php immediately after — it’s a security risk to leave it active.

Cause 4: Restore From a Backup

If the database is too damaged to repair, restore from a recent backup. In cPanel → Backup WizardRestoreMySQL Database, upload your latest .sql.gz backup file.

Don’t have a backup? See How to Back Up Your Website in cPanel to set one up now.

Still Getting the Error?

Contact Veerhost support at veerhost.com/support with your domain name. Our team can check MySQL server status and assist with database recovery.