Troubleshooting "Error Establishing a Database Connection"

When your website shows "Error establishing a database connection," it means your site's software cannot reach the database where its content is stored. This article explains the common causes — most often wrong credentials or a database problem — and how to fix them.

What this error means

Applications like WordPress keep their content in a MySQL database. To read that content, the application signs in to the database using four details stored in its configuration file: the database name, the database user, the password, and the database host. If any of these is wrong, or the database itself is unavailable, the site cannot load and shows this error.

This guide focuses on WordPress, where the error is most common, but the same causes apply to any database-driven site.

Before you begin

  • cPanel access, to check your database details and the configuration file.
  • File Manager or FTP, to view your site's configuration file (wp-config.php for WordPress).
  • A backup, before editing any files or database.

Step 1: Confirm the database login details

The most common cause is a mismatch between the credentials in your configuration file and the actual database.

  1. In File Manager, open your site's folder (usually public_html) and open wp-config.php (or your application's config file).
  2. Note the values for:
    • Database name (DB_NAME)
    • Database user (DB_USER)
    • Password (DB_PASSWORD)
    • Host (DB_HOST) — usually localhost
  3. In cPanel, open MySQL Databases and confirm the database name and username match exactly, including the account prefix. See Creating and Managing MySQL Databases.

Tip: Database names and usernames include an account prefix (like youracct_). A missing prefix is a frequent cause of this error.

Step 2: Reset the database password

If the name and user match but the connection still fails, the password may be wrong.

  1. In cPanel, open MySQL Databases.
  2. Under Current Users, set a new password for your database user. See the database password article.
  3. Update DB_PASSWORD in your configuration file to the new password.
  4. Reload your site.

Step 3: Check the database host

The host value tells the application where the database lives.

  • On Exact Hosting shared plans, this is almost always localhost
  • If your config file has a different host (for example, copied from another provider during a migration), change it to the correct value.

Step 4: Repair the database

If the credentials are all correct, the database itself may be corrupted — common after a heavy traffic spike or a crash.

  1. In cPanel, open MySQL Databases.
  2. Find your database under Modify Databases.
  3. Select the database and run Repair Database
  4. For WordPress, you can also enable its built-in repair tool by adding define('WP_ALLOW_REPAIR', true); to wp-config.php, then visiting yourdomain.com/wp-admin/maint/repair.php. Remove the line when you finish.

Step 5: Rule out a server-side issue

If everything above checks out and the site still cannot connect, the database service may be temporarily overloaded or down.

Next steps

Questions? Contact Exact Hosting Support.

How helpful was this article?

Thanks for your feedback!

Do you still need help? If so please submit a request here.