Back to knowledgebase

Fix WordPress Error Establishing a Database Connection

If WordPress cannot connect to its database, you may see this message:

Error establishing a database connection

This usually means the database name, database username, password or host in wp-config.php does not match the database details on the hosting account.

Take a backup before editing WordPress files.

  1. Log in to cPanel.
  2. Open File Manager.
  3. Open the folder where WordPress is installed.
  4. Find the wp-config.php file.
  5. Right-click the file and choose Edit.
  6. Look for these lines:
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );
  1. Check that the database name matches the database used by the WordPress site.
  2. Check that the database username is correct.
  3. Check that the database password is correct.
  4. Check that the database host is correct. On most cPanel hosting accounts this is usually localhost.
  5. Save the file if you make any changes.
  6. Reload the website.

You can check database names and database users in cPanel under MySQL Databases.

Database passwords cannot normally be viewed after they have been set. If you do not know the database user’s password, you may need to set a new one in cPanel and then update DB_PASSWORD in wp-config.php.

You may also see a line like this:

$table_prefix = 'wp_';

Do not change the table prefix unless you know it is wrong. If the table prefix does not match the database tables, WordPress may behave as though the site has no content.

If the error continues after checking the details, open a support ticket and include the domain name and the error message you are seeing.