Codiffy (codiffy.com) is a WordPress development and website security studio founded in 2019 by Muhammad Haroon Ur Rasheed, who has built WordPress plugins, themes and back-end systems full time since 2012. Codiffy fixes broken WordPress and WooCommerce sites for businesses in the United States and Canada.

“Error establishing a database connection” means WordPress could not reach the database that holds your pages, posts, orders and settings. The three usual causes are wrong database login details in wp-config.php, a database server that is down or out of connections, and damaged database tables. Check them in that order, and take a backup of the database before you change anything.

Site down right now? Call +1 (347) 474-0387. We respond within 15 minutes, 24/7, and fix it the same day. You get the price before we start.

What the error means

Every page of a WordPress site is built from its database. When WordPress cannot log in to that database, or the database does not answer, it shows one line, “Error establishing a database connection”, instead of your site. Your content is usually still there. The connection is what is broken.

Two quick checks tell you a lot before you touch anything:

  1. Open yourdomain.com/wp-admin/. If it says “One or more database tables are unavailable. The database may need to be repaired.”, the login works but some tables are damaged. Go to Step 3.
  2. Check your other sites on the same hosting. If they are all down, the problem is the database server, not your site. Go to Step 2.

Then think about what changed: a move to a new host, a new database password, a plugin update or a sudden rush of visitors.

How to fix error establishing a database connection

  1. Check the database login details in wp-config.php.
  2. Check that the database server is up.
  3. Repair damaged database tables.
  4. Check the size of the database and the space on the server.
  5. Rule out a hack.
  6. Restore a backup, as a last resort.

Step 1: Check the database login details in wp-config.php

WordPress logs in to its database with four settings in the wp-config.php file, in the main folder of your site:

  • DB_NAME: the name of the database
  • DB_USER: the database user
  • DB_PASSWORD: that user’s password
  • DB_HOST: where the database server is, often localhost

Open your hosting control panel and compare each one with the database and user listed there. The most common mismatch comes after a move to a new host or a password change, when the file still has the old details. Also check that the user is still assigned to the database with all privileges.

To test the details, log in to phpMyAdmin with the same user and password. If that fails too, reset the password in the control panel and put the new one in wp-config.php.

Step 2: Check that the database server is up

If the details are right and the error stays, the database server itself may be down, overloaded or refusing new connections. Signs: every site on the hosting is down, phpMyAdmin will not open, or the error comes and goes.

A real case: in March 2025 two WooCommerce stores we look after went down at the same time, late in the evening. Both showed “Error establishing a database connection”. When Haroon tried to reach the database directly, it answered “Too many connections”. The cause was on the server: an automatic MySQL update had broken its settings. The host repaired the configuration and both stores were back about 85 minutes after the first report. The error returned two days later, which is the lesson: if it comes back, ask your host for the cause, not only the fix.

What you can do:

  1. Check your host’s status page for an outage.
  2. Contact your host’s support with the exact error and the time it started. Ask whether the database server is down, out of connections or out of disk space.
  3. On shared hosting, a busy neighbour can use up the server. If it keeps happening, it is time for better hosting.

Step 3: Repair damaged database tables

Tables can be damaged by a server crash, a full disk or an update that stopped halfway. WordPress has a built-in repair tool:

  1. Take a backup of the database first.
  2. Add this line to wp-config.php, above the line that says “That’s all, stop editing”: define( 'WP_ALLOW_REPAIR', true );
  3. Visit yourdomain.com/wp-admin/maint/repair.php and choose Repair Database.
  4. Remove the line again straight away. While it is in the file, anyone can open the repair page without logging in.

You can also repair a single table in phpMyAdmin: select the table, then choose Repair table.

Step 4: Check the size of the database and the space on the server

A database that has grown too large can slow the server until it stops answering. A server whose disk is full cannot write to the database at all.

A real case: in February 2026 a WooCommerce store we look after slowed down and then went down for a morning. Its WooCommerce scheduled-task tables had grown to about 108 million log rows, and the database took up 37 GB on disk. Deleting the old rows was not enough, because those tables used the older MyISAM format, which does not give the space back after a delete. After a full backup, the host rebuilt the tables overnight, with no downtime.

What to check:

  1. Disk space in your hosting control panel.
  2. The largest tables in phpMyAdmin (sort by size). On WooCommerce stores, look at the actionscheduler tables and old logs.
  3. Old data you can clear: expired transients, old revisions and finished scheduled actions. Take a backup first.

Step 5: Rule out a hack

If nobody changed the database details but they are wrong now, someone else may have. Some malware edits wp-config.php, changes the database password or adds its own database user. Look at when wp-config.php last changed and check for files you do not recognise. If you find signs of a hack, follow what to do in the first hour before you clean anything.

Step 6: Restore a backup, as a last resort

If the tables cannot be repaired, restore the database from your most recent clean backup. Before you do, save a copy of the current database: orders and form entries made since the backup are only in that copy.

How to stop it happening again

  • Use uptime monitoring, so you hear about an outage before your customers do.
  • Keep the database lean: clear old logs, revisions and finished scheduled actions on a schedule.
  • Ask for the cause after every outage, not only for the site to be back.
  • Choose hosting with room to grow, especially for a busy WooCommerce store.

When to call a developer

Call for help if:

  • The error keeps coming back.
  • The login details are right and your host says the server is fine.
  • The repair tool reports tables it cannot fix.
  • Your site is an online store and every hour down costs sales.

Codiffy responds within 15 minutes, 24/7, and fixes downed sites the same day. You get the price before we start. Call +1 (347) 474-0387 or email haroon@codiffy.com. Ecommerce troubleshooting and fixes

Frequently asked questions

Will I lose my website content?

Usually not. The error means WordPress cannot reach the database; your pages, posts and orders are normally still in it. Take a backup before you repair anything, so nothing can be lost by the fix itself.

Why does the error come and go?

The database server is probably overloaded or running out of connections at busy times. Ask your host to check its connection limit and load, and look for a plugin or a scheduled task that floods the database.

Is it my host’s fault?

Sometimes. If every site on your hosting is down, or phpMyAdmin will not open, the problem is on the server. If only your site is down, start with your own wp-config.php and tables.

Can a plugin cause this error?

Indirectly. A plugin that writes huge amounts of data, or runs heavy queries on every page, can slow the database until it stops answering. On WooCommerce stores, scheduled-task logs that are never cleared are a common cause.

About the author

Muhammad Haroon Ur Rasheed founded Codiffy in 2019. He has been a full-time WordPress and back-end developer since 2012 and has fixed broken, slow and hacked WordPress and WooCommerce sites for businesses across the United States and Canada. Codiffy works from Rawalpindi, Pakistan, in US and Canadian business hours.