UK web hosting · 24/7 live chat Open a ticket Client login

Guide

How to fix the WordPress database connection error

By Limitless Hosting. Published 8 November 2026. Last updated 8 November 2026.

The message Error establishing a database connection means WordPress cannot talk to its MySQL database. The usual causes are wrong details in wp-config.php, a changed database password, a missing or damaged database, or a server problem. Check the four database settings in wp-config.php first, then confirm the database and user exist, and repair or restore if needed.

See the plans

Meaning

What this error is really saying

WordPress stores nearly everything in a MySQL database: posts, pages, settings, users and comments. Every page load runs a series of database queries. If WordPress cannot open a connection to that database, it cannot build anything, and instead of your site you see a plain white page with the message Error establishing a database connection.

The connection needs four correct values: the database name, the database username, the password and the host. WordPress reads these from the wp-config.php file. If any of them is wrong, or if the database server is not responding, or if the database itself is damaged, the message appears.

The good news is that the content is usually still safe. The error is about the link between WordPress and its data, and not normally about the data being lost. Work carefully and take a backup before changing things.

The chain

What must all work for a WordPress page to load

  1. wp-config.phpHolds the four database details
  2. Database userMust exist with the right password
  3. DatabaseMust exist and be linked to that user
  4. MySQL serverMust be running and reachable
  5. TablesMust be intact and readable

The error appears if any link in this chain breaks. Check them in order, from the left.

Unlimited MySQL databases on every plan

Create as many databases as your projects need, with one-click WordPress too.

WordPress hosting

Step by step

Fixing the error in order

Check whether the admin area also fails

Visit /wp-admin/. If it shows a different message, such as one asking you to repair the database, the connection works and the tables need repair.

Open wp-config.php

Use the file manager or FTP and find the file in the site folder. Look for DB_NAME, DB_USER, DB_PASSWORD and DB_HOST.

Compare with the control panel

In the MySQL databases area, check the exact database name and username, remembering that they usually carry an account prefix. Reset the user password if unsure.

Confirm the user is linked to the database

A user must be added to the database with privileges. If the link is missing, add it with all privileges.

Check DB_HOST

On shared hosting this is normally localhost. Only change it if we have told you a different host is needed.

Test the connection

Use phpMyAdmin from the control panel with the same user. If you can log in and see the tables, the database is healthy.

Repair if needed

If tables are damaged, use the repair tool in phpMyAdmin, or WordPress own repair option described below.

Causes

Likely causes and how to confirm each

CauseHow to confirmFix
Wrong database nameName in wp-config.php differs from the control panelCorrect DB_NAME, including any prefix
Wrong username or passwordphpMyAdmin login fails with those detailsReset the password and update wp-config.php
User not linked to databaseThe database shows no privileged usersAdd the user with all privileges
Wrong hostThe error appears right after a migrationUse localhost unless told otherwise
Damaged tablesAdmin shows a repair messageRepair tables or restore a backup
Database deleted or emptiedphpMyAdmin shows no tablesRestore the database from a backup
Server overloadedThe error comes and goes under trafficAdd caching, check for bot traffic, ask support
Changed salts or URLs onlyDifferent error such as a redirect loopCheck the settings, not the connection

Editing safely

Editing wp-config.php without breaking it

The wp-config.php file is plain text, so you can edit it in the file manager. Download a copy first. Each setting looks like define( DB_NAME, your_database ); with quote marks around the value. Keep the quote marks and the semicolons. A single missing quote can produce a different error, so change only the value inside the quotes.

Special characters in passwords are a common trap. Passwords containing quote marks, backslashes or dollar signs need care when typed into a file. If you cannot get it working, set a new password using only letters and numbers, but make it long and random. Length gives the strength, so a long password without symbols is still strong.

After saving, reload the site in a private window. If you changed a password in the control panel, remember to change it in wp-config.php too, because the file does not update by itself.

Narrowing down

Settings problem or database problem

Looks like a settings problem

  • It started after a migration or copy
  • It started after a password change
  • wp-admin shows the same message
  • phpMyAdmin login fails with the saved details
  • The database name or prefix looks different

Looks like a database problem

  • Nothing changed and it appeared suddenly
  • phpMyAdmin works with the same details
  • Admin asks you to repair the database
  • Tables are missing or marked as crashed
  • It follows a failed plugin update or import

Repair

Repairing a damaged database

If the connection details are right but WordPress reports corrupt tables, you can ask WordPress to repair them. Add the line define( WP_ALLOW_REPAIR, true ); to wp-config.php, then visit yoursite.co.uk/wp-admin/maint/repair.php. Choose Repair Database, and WordPress fixes what it can. This page needs no login, so remove the line from wp-config.php as soon as you finish.

You can also repair from phpMyAdmin: select the database, tick all tables, and choose Repair table from the menu. It works for many tables, though not for every storage type. If repairs fail or content is missing, restoring a backup is the safer route.

We keep weekly remote backups for about a month on every plan, and you should take your own export before major changes. Our backup guide shows how, and when you ask us for a restore, say which date you need and whether it is the files, the database or both.

Checklist

Database error checklist

  • Take a backup before changing anything
  • Check DB_NAME, DB_USER, DB_PASSWORD and DB_HOST
  • Confirm the database exists in the control panel
  • Confirm the user is attached with privileges
  • Log in to phpMyAdmin with the same details
  • Check for crashed tables and repair them
  • Remove WP_ALLOW_REPAIR after use
  • Restore from backup if repairs fail

Prevention

Keeping the connection healthy

Back up regularly

Weekly remote backups are included, and your own export before updates adds safety.

Use object caching

Redis object caching reduces the number of queries the database must handle.

Tidy the database

Remove old revisions, spam comments and leftover plugin tables now and then.

Record credentials safely

Keep database details in a password manager, not in a loose email.

Migrate with care

After moving a site, check wp-config.php straight away.

Ask early

Live chat can check the server side in minutes.

Server side

When the problem is not in your files

If your details are correct, phpMyAdmin works, yet the site still fails now and then, the cause may be load. A sudden burst of traffic, an aggressive bot or a plugin running heavy queries can exhaust connections for a short time. Caching helps a lot here, and so does blocking abusive requests. Our plans use LiteSpeed with Redis object caching available, which lowers the work on the database.

Tell us when it happened and what the site was doing. We can look at the server side and tell you whether the database was overloaded, restarted or limited. Combine that with the advice in our WordPress speed guide to make the site lighter on its database.

FAQ

Common questions

Is my content lost if I see this error?

Usually not. The error is about the link to the database, not the data. Take a backup, then follow the checks above.

Where is wp-config.php?

In the main WordPress folder, the same place as wp-content and wp-admin. Use the file manager or FTP.

What should DB_HOST be?

Normally localhost on shared hosting. Change it only if told to.

Why did it break after a migration?

The new database name, user or password differ from the old ones and wp-config.php was not updated.

Can I fix it without technical knowledge?

Often yes by following the steps. If not, live chat can check the details with you.

WordPress hosting with databases to spare

Unlimited MySQL databases and Redis caching on every plan.

See the plans .co.uk and .uk domains £9.99

From 84p a month, billed yearly
15-day money back
Get started