Error Establishing a Database Connection in WordPress: Complete Fix and Monitoring Guide

This is the scariest page your WordPress site can show. Here is exactly what causes it, how to fix it, and how to make sure you never find out about it from a customer again.

The worst WordPress error you can get

You are browsing your own website and instead of your homepage, you see a white page with one line of text:

"Error establishing a database connection."

That is it. No header. No footer. No content. Just that sentence. And if you are seeing it, so is every single person trying to visit your site right now.

This is not a minor glitch. When WordPress cannot connect to its database, your entire site is gone. Every page, every post, every product, every form. The front end is dead. If you have WooCommerce, orders are not going through. If you have a membership site, nobody can log in. If you rely on organic traffic, Google is crawling a broken page and quietly reconsidering your rankings.

The painful part? This error can happen at 3am and sit there for hours. Unless someone happens to visit your site and tells you about it, you have no idea. Your hosting dashboard might show everything as "operational." Your server is technically running. It is just not serving your website.

What actually causes this error

WordPress stores everything in a MySQL database — your content, settings, users, plugin configurations, everything. When WordPress loads a page, it connects to that database, runs queries, and assembles the page from the results. If that connection fails for any reason, you get this error.

There are four common causes, and each one requires a different fix.

1. Wrong database credentials in wp-config.php

This is the most common cause after a migration or hosting change. Your wp-config.php file contains four critical values:

  • DB_NAME — the name of your database
  • DB_USER — the database username
  • DB_PASSWORD — the database password
  • DB_HOST — the database server address (usually localhost)

If any of these are wrong, WordPress cannot connect. This happens when you migrate to a new host and forget to update the credentials, when your hosting provider changes the database server address, or when someone accidentally edits the file.

How to fix it: Open wp-config.php via FTP or your hosting file manager. Check each value against your hosting control panel's database settings. The WordPress wp-config.php documentation explains exactly what each value should be. Pay special attention to DB_HOST — on shared hosting it is usually localhost, but on some providers like AWS RDS or managed MySQL it is a full hostname.

2. MySQL server has crashed or is not running

Your database credentials can be perfectly correct, but if the MySQL server itself is down, nothing connects. This happens more often than you would think, especially on shared hosting where hundreds of sites share the same database server.

Common triggers include: the hosting provider running out of memory and killing MySQL to free resources, a traffic spike on another site on the same shared server, a failed MySQL update, or a corrupted InnoDB tablespace.

How to fix it: If you have SSH access, check if MySQL is running with sudo systemctl status mysql. If it is stopped, restart it with sudo systemctl restart mysql. On shared hosting, you cannot do this yourself — contact your host. If MySQL keeps crashing, check the MySQL error log (usually at /var/log/mysql/error.log) for out-of-memory errors or table corruption messages.

The MySQL troubleshooting documentation covers the most common startup failures in detail.

3. Database connection limits exceeded

Every MySQL server has a maximum number of simultaneous connections. When your site gets a traffic spike, or when a misbehaving plugin opens connections without closing them, you can hit that limit. Once you do, new connections are refused — and WordPress shows the database error.

This is especially common on shared hosting where the connection limit is low (often 25 to 50 connections), and on WooCommerce sites during flash sales or promotional events.

How to fix it: First, check if a plugin is the culprit. Deactivate plugins one by one (via FTP if you cannot access wp-admin — rename the plugin folder in /wp-content/plugins/). Install a persistent object cache like Redis or Memcached to reduce database queries. If you are on shared hosting and hitting limits regularly, it is time to upgrade to a VPS or managed WordPress host with dedicated MySQL resources.

4. Corrupted database tables

MySQL tables can become corrupted after a server crash, a failed write operation, or disk issues. When WordPress tries to read from a corrupted table, the query fails and the connection error appears.

How to fix it: Add this line to your wp-config.php temporarily:

define('WP_ALLOW_REPAIR', true);

Then visit yoursite.com/wp-admin/maint/repair.php. WordPress will attempt to repair and optimise all database tables. Once finished, remove the line from wp-config.php immediately — leaving it in place lets anyone trigger a repair without authentication.

For more advanced repair, use phpMyAdmin from your hosting panel. Select all tables, choose "Repair table" from the dropdown, and run it. The WordPress database optimisation guide covers additional optimisation techniques.

The real problem: you did not know it was happening

Here is the thing that nobody talks about with this error. Fixing it is usually straightforward once you know it is happening. The real damage comes from the hours or days it sits there undetected.

Think about it. When was the last time you manually checked your own website? Not your dashboard — your actual public-facing site. If you are like most site owners, it has been days. Maybe weeks. Your WordPress site could be showing this error right now and you would not know.

And the error is invisible to most basic monitoring. Here is why: when WordPress shows "Error establishing a database connection," your web server is still running. Apache or Nginx is still responding to HTTP requests. Some hosts even return a 200 OK status code with the error message in the body. So a simple uptime check that only looks at HTTP status codes will report your site as "up."

Your site is up. It is just not working.

How to monitor for this error with Uptrue

This is exactly the kind of failure that Uptrue is built to catch. You need two types of monitors working together: an HTTP monitor and a keyword monitor.

Step 1: Set up an HTTP monitor

The HTTP monitor is your first line of defence. It checks that your site responds at all.

  1. Sign up at uptrue.io/signup (free plan available)
  2. Click Add Monitor from your dashboard
  3. Select HTTP/HTTPS as the monitor type
  4. Enter your WordPress site URL (your homepage)
  5. Set the check interval to 1 minute
  6. Set expected status code to 200
  7. Configure your alert channels — Slack, email, or Microsoft Teams

This catches the cases where MySQL is completely down and your server returns a 500 error. But it will not catch the cases where the server returns a 200 status with the error message in the body.

Step 2: Set up a keyword monitor (this is the critical one)

The keyword monitor is what catches the sneaky failures. It checks that specific text exists on your page — or that specific text does not exist.

  1. Click Add Monitor again
  2. Select Keyword as the monitor type
  3. Enter your homepage URL
  4. Set the keyword to your site name or a phrase that always appears on your homepage (like your tagline or a menu item)
  5. Set the check type to "Page must contain"
  6. Set the interval to 1 minute

Now, if WordPress shows "Error establishing a database connection" instead of your actual content, the keyword monitor will not find your expected text. It triggers an alert immediately.

For extra protection, add a second keyword monitor:

  1. Same URL, same settings
  2. Set the keyword to "Error establishing a database connection"
  3. Set the check type to "Page must NOT contain"

This one fires the moment that specific error text appears on your site. Between these two monitors, the database error has nowhere to hide.

Step 3: Set up a status page (optional but smart)

If you run a site that your clients or customers depend on, set up a public status page. When the database error hits, your monitors trigger, your status page updates automatically, and your users can check the status themselves instead of flooding your inbox asking "is the site down?"

Step 4: Check your site health right now

Before you set up monitoring, run a free health check on your site. It analyses your uptime, SSL, DNS, security headers, and performance — and shows you exactly where your vulnerabilities are.

Check your WordPress site health for free

Instant health score across uptime, SSL, DNS, security headers, and performance. No account required.

Check Your Website Score

Preventing the error before it happens

Monitoring catches the error fast. But you should also reduce the chances of it happening in the first place.

Keep your wp-config.php credentials documented

Store your database credentials securely outside your hosting panel. If you ever need to migrate or troubleshoot, you want immediate access without digging through support tickets.

Monitor your hosting resource usage

Most hosting panels show CPU, memory, and MySQL connection usage. If you are consistently running above 80% on any of these, you are one traffic spike away from a database error. Consider upgrading before it becomes a problem.

Optimise your database regularly

WordPress accumulates post revisions, transient options, spam comments, and orphaned metadata over time. Use a plugin like WP-Optimize to clean up your database monthly. Fewer rows means faster queries means fewer connection timeouts.

Use a persistent object cache

Redis or Memcached stores frequently-accessed data in memory so WordPress does not need to hit the database for every page load. This dramatically reduces the number of database connections and makes your site more resilient under load.

Choose hosting with dedicated MySQL resources

Shared hosting means shared database servers. When another site on the same server gets a traffic spike, your database slows down or becomes unreachable. Managed WordPress hosting or a VPS with dedicated MySQL resources eliminates this risk.

Stop finding out from your customers

Your WordPress site could be down right now and you would not know.

Uptrue monitors your site every 60 seconds and alerts you on Slack, email, or Teams the moment something goes wrong — from full outages to subtle content changes that only a keyword monitor catches.

The database connection error is one of the most common WordPress failures, and one of the hardest to detect with basic monitoring. A simple HTTP check is not enough. You need keyword monitoring that checks what your page actually says.

Never discover database errors from your customers again.

Start monitoring your WordPress site in 60 seconds

Free plan available. HTTP and keyword monitoring. AI-powered reports. No credit card required.

Frequently asked questions

What does "Error Establishing a Database Connection" mean in WordPress?

This error means WordPress cannot connect to its MySQL database. WordPress stores all your content, settings, users, and pages in a database. When it cannot reach that database — because of wrong credentials, a crashed MySQL server, exceeded connection limits, or corrupted tables — it shows this error instead of your website.

Can this error happen even if my hosting is up?

Yes. Your web server (Apache or Nginx) can be running perfectly while your MySQL database server is down, overloaded, or unreachable. Standard uptime monitoring that only checks HTTP status codes may report your site as "up" because the server still returns a response — it just returns an error page. This is why keyword monitoring is critical: it checks for expected content, not just a response.

How do I prevent the WordPress database connection error from happening again?

Three things help: First, use a reliable hosting provider with dedicated MySQL resources. Second, keep your WordPress plugins and database optimised to avoid connection limit exhaustion. Third, set up continuous monitoring with both HTTP checks and keyword monitoring so you are alerted the moment the error appears — before your visitors notice.

Will a caching plugin prevent this error?

A caching plugin can reduce the number of database queries, which helps with connection limit issues. However, if MySQL crashes or your wp-config.php credentials are wrong, caching will not help — once the cache expires, visitors will see the error. Caching is a performance optimisation, not a reliability solution. You still need monitoring.