# Fixing "Error establishing a database connection"

> Your site shows "Error establishing a database connection" or a similar database error. Here's how to find the cause and fix it.

Source: https://helpcenter.ruachost.com/cpanel/databases/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

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](https://helpcenter.ruachost.com/cpanel/databases/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

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](https://helpcenter.ruachost.com/cpanel/databases/managing-mysql-databases-and-users/).

## 3. Check the database still exists

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](https://helpcenter.ruachost.com/cpanel/files/restoring-files-email-and-databases-using-jetbackup/).

## 4. Check for damaged tables

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](https://helpcenter.ruachost.com/cpanel/databases/optimizing-and-repairing-mysql-databases-using-phpmyadmin/), or in WordPress, [Fixing database table problems](https://helpcenter.ruachost.com/wordpress/guides/fixing-database-table-problems-in-wordpress/).

## 5. Too many connections?

If the error comes and goes when your site is busy, it may be reaching the limit of simultaneous connections. See [Common MySQL errors](https://helpcenter.ruachost.com/cpanel/databases/common-mysql-errors/).

## 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](https://helpcenter.ruachost.com/getting-started/website-troubleshooting/help-resource-limit-has-been-reached/).

Still not working? [Open a support ticket](https://dashboard.ruachost.com/submitticket.php) and tell us your site's address and when the error started.
