The error means WordPress cannot log in to its MySQL database. To fix it, check the database name, username, password, and host in wp-config.php, confirm with your host that the database server is running, repair damaged tables with the built-in repair tool, and restore a recent backup if nothing else works.

Many business owners describe a morning like this one (a composite story, details changed). Marcus owns a small bakery that takes cake orders through its website. One Friday, a single plain sentence replaced his whole menu. He searched the WordPress error establishing a database connection and found pages full of terms like “MySQL” and “DB_HOST.” He worried he had lost every order and every recipe page. Before his first agency call, he feared he would sound clueless or get talked into a rebuild he did not need. In the first few minutes, the consultant explained that the data usually stays safe and the site simply cannot reach it. Marcus realized the call was a conversation about his bakery and his goals, not a sales pitch.

What Does “Error Establishing a Database Connection” Mean?

“Error establishing a database connection” means WordPress tried to open its MySQL database and failed, so it cannot build any page. Every post, page, and setting lives in that database, so the whole site and admin area show the same message.

Quick answer: WordPress stores your content in a separate MySQL database. When WordPress cannot log in to that database or the database server stops responding, every page shows this error. In most cases your content still exists; the site just cannot reach it.

Think of the database as a filing cabinet and wp-config.php as its key. The error means the key failed, not that someone emptied the cabinet.

What Causes the WordPress Error Establishing a Database Connection?

Five problems cause almost every WordPress database connection error: wrong credentials in wp-config.php, a database server that is down or overloaded, corrupted database tables, damaged core files, and a database host value that does not match your hosting setup. Here is how each one usually shows up:

  • Wrong credentials: A host reset the password, or someone edited wp-config.php by mistake.
  • After a migration: wp-config.php still points to the old server’s database.
  • Server problems: Shared hosting plans can hit connection limits during traffic spikes.
  • Corrupted tables: A failed update, a server crash, or malware damaged them.
  • Localhost setups: On XAMPP, a stopped MySQL service or a wp-config.php typo triggers it.

If you see a blank page or a different message instead, start with our guide to fixing a WordPress site that will not load.

How to Check Your wp-config.php Database Settings

The wp-config.php file stores four WordPress database settings (DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST), and one wrong character in any of them breaks the connection. Compare each value with the database details in your hosting control panel. Work through these two checks in order:

Find the four database settings

Open your hosting File Manager or an FTP app, go to the main WordPress folder, and download a copy of wp-config.php before you change anything. Inside, look for four lines that start with define. DB_NAME is the database name, DB_USER is the username, DB_PASSWORD is the password, and DB_HOST is the server address, which is often localhost. Each value sits inside single quotes. A missing quote, an extra space, or a stray semicolon breaks the whole file, so edit slowly and save a backup copy first.

Confirm them in your hosting control panel

Next, open the MySQL Databases area in cPanel or your host’s dashboard and compare the database name and username letter by letter. You cannot view a stored password, so reset it, then paste the new one into wp-config.php. Confirm the user has All Privileges on the database. Many managed hosts use a remote DB_HOST value instead of localhost, so check their documentation. If the error started right after a move to new hosting, a WordPress platform and data migration specialist can trace every setting the move changed.

How to Repair a Corrupted WordPress Database

WordPress includes a built-in repair tool that fixes damaged database tables. You turn it on with one line in wp-config.php, run it from a special web address, and turn it off again when you finish. Choose one of these two methods:

Use the built-in WordPress database repair tool

Add this line to wp-config.php, just above the line that says “stop editing”:

define( ‘WP_ALLOW_REPAIR’, true );

Then visit yoursite.com/wp-admin/maint/repair.php and click Repair Database, or Repair and Optimize Database for a deeper pass. The repair usually finishes within a few minutes. The official wp-config.php documentation notes that anyone can open that page without logging in. Delete the line as soon as the repair finishes, so strangers cannot run the tool on your site.

Repair tables in phpMyAdmin

phpMyAdmin is a database tool that most hosting control panels include. Open it, select your WordPress database in the left column, and tick the box to select every table. Then choose Repair table from the dropdown menu at the bottom. phpMyAdmin checks each table and reports which ones it fixed. Export a copy of the database first, using the Export tab, so you can roll back if anything goes wrong. If phpMyAdmin itself cannot connect to the database, stop here, because the database server is the real problem, not the tables.

What to Do When the WordPress Database Server Is Down

When your credentials match and phpMyAdmin also fails to connect, the MySQL server is usually down or overloaded, and only your hosting provider can restart it. Shared hosting plans hit this limit most often.

Check your host’s status page, then test other sites on the same account. If they fail too, the server is the cause. Tell support the exact error, when it started, and what you already checked. If the error keeps returning, your plan may not have enough resources for your traffic, and it helps to know what a good web host should do for you.

How to Restore a WordPress Database From a Backup

Restoring a backup brings back a working database when repairs fail or malware or a bad update damaged the data. Choose the newest backup from before the error began.

Use your host’s restore tool, a plugin such as UpdraftPlus, or import a saved .sql file through phpMyAdmin. A restore removes anything added after the backup date, such as new orders, so note recent activity first. If you suspect hacking, pair the restore with a WordPress security review so the attacker cannot simply return.

Quick answer: Three habits prevent most repeat database errors: keep WordPress, plugins, and themes updated, store daily backups off the server, and choose a hosting plan with enough resources for your traffic.

A WordPress maintenance program can handle that work for you.

Conclusion

The WordPress database error looks alarming, but your content usually still exists. Start with the four settings in wp-config.php, then repair the tables, then ask your host about the database server. Keep a recent backup stored off the server, because restoring one is the safety net when every other fix fails, and steady maintenance stops most repeat outages. If you would like a second opinion, Quadshot Digital is glad to start with a simple, no-pressure conversation about your site and your goals.

Frequently Asked Questions

Will I lose my website content because of this error?

Usually not. In most cases WordPress simply cannot reach the database, and your posts and orders stay safe inside it. Real data loss happens only when tables are badly corrupted or someone deleted the database. A recent backup protects you in both cases, so check that your host or plugin creates one every day.

Why does the database connection error keep coming back?

A recurring error usually points to the database server rather than your settings. Shared hosting plans can run out of database connections during traffic spikes, then recover a few minutes later. Ask your host whether your account hit a resource limit, and consider caching or a larger plan.

Can a plugin or theme cause the database connection error?

A plugin or theme rarely causes the error directly, but a badly built one can corrupt tables or overload the database. If the error started right after you updated an add-on, rename the plugins folder in your File Manager to switch every plugin off, then test the site again.

Is localhost always the correct database host?

No. Many hosts use localhost, but some managed WordPress hosts run the database on a separate server with its own address, sometimes with a port number. Check your hosting dashboard or support documentation for the exact DB_HOST value, and copy it into wp-config.php without changing anything.