Skip to content
Free website migration on every plan, done by our team.Learn more ›
WordPress

Fix "Error establishing a database connection" in WordPress

Fix WordPress's "Error establishing a database connection": check wp-config.php details, the database server, user privileges and repairs.

Short answer: WordPress can't reach its database. In most cases the database name, username, password or host in wp-config.php is wrong, the database user lost its privileges, or the database server is briefly overloaded. Check those four things in order and the site usually comes back in minutes.

1. Check the details in wp-config.php

Open wp-config.php in cPanel's File Manager and compare these four lines with what cPanel shows under MySQL Databases:

  • DB_NAME: the full database name, usually with your account prefix
  • DB_USER: the database user, also prefixed
  • DB_PASSWORD: the user's password
  • DB_HOST: usually localhost on cPanel hosting

If you've just moved hosts, this is almost always the cause. See how to move WordPress to a new host.

2. Make sure the user is attached to the database

In MySQL Databases, scroll to Add User to Database, choose the user and the database, and grant All Privileges. A user that exists but isn't attached produces exactly this error.

3. Reset the database password

If you're not sure of the password, set a new one for the database user in cPanel and paste the same password into DB_PASSWORD.

4. Repair the database

If the error appears only on some pages or says tables are corrupt:

  1. Add define('WP_ALLOW_REPAIR', true); to wp-config.php.
  2. Visit yourdomain.com/wp-admin/maint/repair.php and run Repair Database.
  3. Remove the line again afterwards, because the repair page doesn't require a login.

5. Check for overload

A traffic spike or a heavy plugin can exhaust the database connections your plan allows. If the error comes and goes, enable caching (see caching explained) and look at resource usage in cPanel.

When to contact your host

If the details are correct and the error persists, the database service itself may be down. Message AuroxHost support on WhatsApp and we'll check the server for you.

Frequently asked questions

Will I lose my content because of this error?

Usually not. The content is still in the database; WordPress just can't connect to it. Keep a recent backup anyway. See WordPress backups.

Why did it start after changing my hosting password?

Your cPanel password and your database user's password are separate. Only the database password in wp-config.php matters here.

Is DB_HOST always localhost?

On most cPanel hosting, yes. Some hosts use a separate database server; your host's documentation or support will tell you.

Ready when you are

Host it where it performs

NVMe speed, offshore privacy and a written SLA — live in minutes on AuroxHost.