Skip to content

Fixing "Error establishing a database connection"

“Error establishing a database connection” (WordPress), “Database connection error” (Joomla) and similar messages mean your website can’t reach its database. The site itself is fine; it just can’t load its content. Work through these checks.

1. Check the database details in your site’s configuration

Section titled “1. Check the database details in your site’s configuration”

The most common cause, especially after moving a site or changing a password. Your site’s configuration file must contain the correct database name, username, password and host.

Application File Settings to check
WordPress wp-config.php DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
Joomla configuration.php $db, $user, $password, $host
Laravel .env DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_HOST

Compare them with your details in cPanel. See Finding your database details. Remember:

  • Names include your cPanel username prefix, e.g. cpuser_wp123.
  • The host should be localhost.
  • If you’re not sure of the password, set a new one in Manage My Databases → Current Users → Change Password, then put the same password in the configuration file.

2. Check the user is added to the database

Section titled “2. Check the user is added to the database”

In cPanel’s Manage My Databases, look at Current Databases. Your database user must be listed under Privileged Users for the database. If not, add it under Add User to Database with All Privileges. See Managing MySQL databases and users.

If the database is missing from Current Databases, it may have been deleted. Restore it from your automatic backups. See Restoring files, email, and databases using JetBackup.

If the error is intermittent, or WordPress says “One or more database tables are unavailable”, repair the tables in phpMyAdmin. See Optimizing and repairing MySQL databases using phpMyAdmin, or in WordPress, Fixing database table problems.

If the error comes and goes when your site is busy, it may be reaching the limit of simultaneous connections. See Common MySQL errors.

6. Is your account suspended or over its limits?

Section titled “6. Is your account suspended or over its limits?”

Check that your hosting account is active and hasn’t run out of disk space or resources. See Help! Resource limit has been reached.

Still not working? Open a support ticket and tell us your site’s address and when the error started.