> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hostcloud.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Fix "Error establishing a database connection"

> Get your WordPress site back online when it can't reach its database.

This error means WordPress can't connect to the database that stores your content. Your content is usually still safe. Work through these checks in order.

> [!NOTE]
>
> Is your hosting active? A suspended account shows errors too. In the Client Area, click **Services** and check your hosting shows **Active**. See [Overdue invoices and suspension](/billing/overdue-and-suspension.md).

## 1. Check the details in wp-config.php

Most often, the database details WordPress uses don't match the real ones, for example after moving the site or changing a password.

**1. Open wp-config.php**

[Log in to cPanel](/cpanel/log-in-to-cpanel.md), open **File Manager**, go to your site's folder (usually `public_html`), and open `wp-config.php` with **Edit**.

**2. Note the database details**

Find these lines:

```php theme={null}
define( 'DB_NAME', 'username_wp123' );
define( 'DB_USER', 'username_wpuser' );
define( 'DB_PASSWORD', '...' );
define( 'DB_HOST', 'localhost' );
```

`DB_HOST` should be `localhost`.

**3. Compare with cPanel**

In cPanel, open **Manage My Databases**. Check that a database with exactly the `DB_NAME` exists, a user with exactly the `DB_USER` exists, and that user is listed under the database's **Privileged Users**.

## 2. Reset the database user's password

If the names match, the password may be wrong.

**1. Set a new password**

In **Manage My Databases**, find the user under **Current Users**, choose to change its password, and set a new strong password. Copy it.

**2. Update wp-config.php**

Paste the new password into the `DB_PASSWORD` line in `wp-config.php`, keeping the quote marks, and save the file.

Reload your site.

## 3. If the user isn't linked to the database

In **Manage My Databases**, under **Add User To Database**, choose the user and the database, click **Add**, and tick **ALL PRIVILEGES**.

## 4. Repair the database

If only part of your site shows the error, or the admin dashboard mentions a damaged database:

**1. Turn on repair mode**

Add this line to `wp-config.php`, just above the line `/* That's all, stop editing! */`:

```php theme={null}
define( 'WP_ALLOW_REPAIR', true );
```

**2. Run the repair**

Visit `https://yourdomain.com/wp-admin/maint/repair.php` and click **Repair Database**.

**3. Turn repair mode off**

Remove the line from `wp-config.php` straight away. While it's there, anyone can open the repair page.

## 5. Check your resource limits

A busy site can hit its limits, so the database can't accept more connections for a while. In cPanel, open **Resource Usage**. See [Check disk and resource usage](/cpanel/check-disk-and-resource-usage.md).

## Still broken?

Restore your database from a daily backup with **Backuply**. See [Restore and download backups](/cpanel/take-and-restore-backups.md). Or [open a Technical Support ticket](/support/open-a-ticket.md) with your domain name, and we'll take a look.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.