---
title: Fix error establishing a database connection
description: "Work through the three checks that clear a WordPress database connection error: the wp-config.php values, the cPanel database user, and a table repair."
date: 2026-11-17
updated: 2026-12-05
tags: [wordpress, phpmyadmin]
url: "https://drivenhost.com/kb/kb-fix-database-connection-error"
author: DrivenHost
---

When a WordPress site shows "Error establishing a database connection", WordPress itself is running but cannot reach its database. The cause is usually one of two things: the database details saved in `wp-config.php` no longer match the database user in cPanel, or a table needs repairing. This guide works through the checks in order, starting with the least disruptive.

You will need to log in to cPanel for all three sections. Take a backup of the site's files and database first, so you can put a value back if you change the wrong one.

## Read the database details in wp-config.php

1. In cPanel, open File Manager.
2. Open the folder that holds the site. For your main domain that is usually `public_html`. For an addon domain or a subdomain it is the folder you chose when you added it, which you can confirm in the Domains area of cPanel.
3. Select `wp-config.php`, then choose Edit from the toolbar. If an encoding prompt appears, continue past it.
4. Note the four values near the top of the file: `DB_NAME`, `DB_USER`, `DB_PASSWORD` and `DB_HOST`.

On a cPanel server, database and user names normally begin with your cPanel username followed by an underscore. `DB_HOST` is usually `localhost`. If yours is set to something else, leave it alone for now, since some setups do use a different host. WordPress documents this file at [Editing wp-config.php](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/).

## Check the database and user in cPanel

1. Return to the cPanel home screen and open MySQL Databases.
2. Under Current Databases, confirm a database exists with exactly the name in `DB_NAME`. A missing database, or one letter out of place, produces this error on its own.
3. Under Current Users, confirm the user from `DB_USER` is listed.
4. Still under Current Databases, check that the user appears beside that database in the privileged users column. If it does not, scroll to Add a User to a Database, pair the two, and grant ALL PRIVILEGES.
5. If you cannot confirm the password, set a new one under Current Users, then edit `wp-config.php` again and paste the same password into `DB_PASSWORD`. Save the file.

Load the site again. If the error has cleared, you are finished.

## Repair the tables in phpMyAdmin

1. From the cPanel home screen, open phpMyAdmin.
2. Select the site's database in the left-hand list.
3. At the foot of the table list, select Check All.
4. Open the With Selected menu, choose Repair Table, and wait for the result screen.
5. Repeat with Check Table if you want to see which tables reported a problem.

Load the site again.

## If it didn't work

- You edited the wrong copy. Staging folders and older installs keep their own `wp-config.php`. Confirm the document root for the domain in the Domains area of cPanel, then check the file in that folder instead.
- The error comes and goes rather than appearing every time. That pattern points at the server or at an account hitting a resource limit, not at your credentials. Stop changing settings and send us a ticket.
- Something else still holds the old details, such as an object cache drop-in file in `wp-content` or a caching plugin's configuration left behind by a move from your previous host.

If the site still shows the error after these checks, open a ticket at [/support](/support) with the domain name and roughly when the error started, and we will check the server side for you.
