Applies to: All plans.
"Error establishing a database connection" means WordPress loaded but could not reach its MySQL database. Nine times out of ten the cause is wrong database details in your wp-config.php file, a database user that has lost its privileges, or a corrupted database table. This guide shows you how to check each one in cPanel.
The web pages are fine; only the link between WordPress and its database is broken. Your files and your database almost certainly still exist.
Symptoms
- Every page of your site shows the white message "Error establishing a database connection", often with nothing else.
- The WordPress admin (/wp-admin) shows the same error or offers to repair the database.
- The error appeared suddenly after editing wp-config.php, moving the site, or changing a database password.
Common causes (most likely first)
- Wrong database credentials in wp-config.php — the database name, user, password or host no longer match what exists in cPanel. This is by far the most common cause, especially after a migration or a password reset.
- The database user has no privileges on the database — the user exists but is no longer attached to the database with full permissions.
- A corrupted database table — a table was damaged (often after a resource spike) and MySQL cannot serve it.
- The account is over its resource limits — under heavy load MySQL connections can be refused briefly. This usually clears on its own; see the related article on 508 errors.
Quick fixes
1. Check your wp-config.php credentials
- Log in to cPanel (open your service in the client area -> Services -> My Services, then Log in to cPanel).
- Open cPanel -> Files -> File Manager and go to your site's folder (for the main domain this is usually public_html).
- Find wp-config.php, select it and choose Edit. Note these four values:
define( 'DB_NAME', '...' );define( 'DB_USER', '...' );define( 'DB_PASSWORD', '...' );-
define( 'DB_HOST', '...' );— on our servers this should belocalhost.
- In a second tab, open cPanel -> Databases -> MySQL Databases. Confirm a database with the exact DB_NAME exists and a user with the exact DB_USER exists. Database and user names include your cPanel account prefix (for example
acct_wp), so copy them carefully. - If you are unsure of the password, set a fresh one: in MySQL Databases find the user under Current Users, choose Change Password, set a new password, then paste that exact password into DB_PASSWORD in wp-config.php and save.
Result: When the four values in wp-config.php match a real database and user in cPanel, reload your site. The error should be gone.
2. Confirm the user is attached with full privileges
- In cPanel -> Databases -> MySQL Databases, scroll to Add User To Database.
- Pick your DB_USER and your DB_NAME and click Add.
- On the privileges screen, tick ALL PRIVILEGES, then Make Changes.
Result: The user can now read and write the database. Reload your site to confirm.
3. Repair a corrupted database
- Open cPanel -> Databases -> phpMyAdmin and select your database in the left-hand list.
- Tick the box to select all tables, then from the With selected drop-down at the bottom choose Repair table.
- Reload your site.
You can also let WordPress try its own repair: temporarily add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php, visit https://yourdomain/wp-admin/maint/repair.php, run the repair, then remove that line again.
If that did not work
- Test the credentials directly. If phpMyAdmin will not open your database with the DB_USER and password from wp-config.php, the credentials are still wrong — repeat step 1.
- Restore the database from a backup. If a table is too damaged to repair, restore a recent copy with JetBackup. See How to restore a database.
- Rule out a resource spike. If the error comes and goes under traffic, check your usage — see Resource limit reached and 508 errors explained.
- Note on email: WordPress's database is separate from your mailboxes, so this error does not affect your email, whether it's a mailbox on your plan or Professional Email (Microsoft 365 or Google Workspace). What does stop is the mail WordPress sends itself (contact forms, password resets, order emails) until the site works again.
Comments
0 comments
Please sign in to leave a comment.