"Error establishing a database connection" means WordPress can't talk to its MySQL database, so it can't load any page. The good news is that the database itself is almost always fine -- it's usually a mismatch between the login details in wp-config.php and the database user in cPanel. This guide walks you through finding and fixing the WordPress database connection error step by step.
Common causes
- The database password in
wp-config.phpdoesn't match the database user's password (often after someone changed it in cPanel). - The database name or username is wrong -- for example after moving the site from another host.
- The database user was never added to the database, or lost its privileges.
- A damaged database table.
- Your account hit its resource limits for a moment during a traffic spike.
Step 1: Look at the database details in wp-config.php
- Log in to cPanel and go to Files > File Manager.
- Open
public_html(or the folder where WordPress is installed), selectwp-config.phpand click Edit. - Find these lines and note the values:
define( 'DB_NAME', 'cpuser_wp123' ); define( 'DB_USER', 'cpuser_wpuser' ); define( 'DB_PASSWORD', 'the-password' ); define( 'DB_HOST', 'localhost' );
On Instant Access Internet Services servers, database names and usernames always start with your cPanel username and an underscore, and DB_HOST should be localhost.
Step 2: Check the database and user exist in cPanel
- In cPanel, go to Databases > Manage My Databases.
- Under Current Databases, check that a database with exactly the
DB_NAMEvalue exists. - In the same row, look at the Privileged Users column. The
DB_USERvalue should be listed there.
If the names don't match anything, the site may be pointing at an old database. Correct DB_NAME and DB_USER in wp-config.php to match the database and user shown in cPanel.
Step 3: Reset the database user's password
This is the fix in most cases. You set a new password in cPanel, then put the same password in wp-config.php.
- In Databases > Manage My Databases, scroll to Current Users.
- Next to the user from
DB_USER, click Change Password. - Enter a new strong password (or use the Password Generator) and copy it. Click Change Password.
- Back in File Manager, edit
wp-config.phpand paste the new password between the quotes on theDB_PASSWORDline. Be careful not to remove the quote marks or the semicolon. - Click Save Changes and reload your website.
Step 4: Make sure the user has privileges on the database
- In Manage My Databases, go to Add User To Database.
- Choose the user from
DB_USERand the database fromDB_NAME, then click Add. - Tick ALL PRIVILEGES and click Make Changes.
Step 5: Repair the database
If the details are all correct but the error continues, or the WordPress admin says one or more tables are unavailable, repair the database:
- In Manage My Databases, find Modify Databases.
- Choose your database under Repair Database and click Repair Database.
Still getting the error?
- It comes and goes. If the site works most of the time but shows the error during busy periods, check Metrics > Resource Usage for limit hits. Turning on LiteSpeed Cache usually fixes this.
- It started after a restore or migration. The database may be empty or missing. Check in Databases > phpMyAdmin that the database has tables. If not, restore the database with JetBackup 5.
- It started after a hack or plugin change. Restore from a backup taken before the problem, then change your passwords.
Related guides
- How to Change a MySQL Database User's Password
- How to Create a MySQL Database and User in cPanel
- How to Restore a MySQL Database with JetBackup 5
- How to Edit a File in cPanel File Manager
- How to Speed Up WordPress with LiteSpeed Cache
Still stuck? Open a support ticket and the Instant Access Internet Services team will help.
