Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Error establishing a database connection: how to fix it

OPS-075High impactDetectedBy FunnelGuardPublished Updated
On this page

What this issue is

Most dynamic sites store pages, products, orders and settings in a database such as MySQL or MariaDB. On every request, the site opens a connection to it. If that connection fails, WordPress shows Error establishing a database connection. Other platforms show a blank page, a 500 error or their own message.

The page you see is often plain white with one line of text. Your header, forms, tracking tags and checkout are all gone, because nothing can be built without data.

Why it costs you leads or sales

While the error shows, nobody can view a landing page, submit a form or pay. If you run ads, you keep paying for clicks that land on an error page. Tracking tags never load either, so the visits may not even appear in your analytics.

The error can also be intermittent. A database that is slightly overloaded may fail for a few visitors and work for others, which makes it easy to miss.

Where the funnel breaks
  1. Ad clickVisitor arrives from your campaign
  2. Database connectionSite cannot connect to MySQL
  3. Landing pageShows an error message
  4. Form or checkoutNever reached
  5. Lead or orderNot recorded

The site cannot reach the database, so every later step is lost.

Leads during a database outageExample numbers
Leads during a database outage (example)Normal hour: 12 leads per hour; Outage hour: 0 leads per hour059120Normal hourOutage hourleads per hour

Example: a site that normally gets 12 leads an hour drops to zero while the database is unreachable.

How to check if your site has it

Confirm and narrow down the cause
  1. Reload the page and the admin

    Open the front page and /wp-admin (WordPress). If the admin shows 'One or more database tables are unavailable' or a repair message, the tables are damaged. If both show the connection error, the credentials or server are the likely cause.

  2. Try another device or network

    Rule out your own cache or connection. Use a private window or mobile data.

  3. Check your host's status page and control panel

    Look for a database or MySQL incident, and check that your database exists and its disk quota is not full.

  4. Test the credentials directly

    Log in to phpMyAdmin or run a mysql command with the same user and password found in wp-config.php.

Test the database login from the command linebash
mysql -h localhost -u DB_USER -p DB_NAME -e "SELECT 1;"

If this command fails with 'Access denied', the user or password is wrong. If it fails with 'Can't connect', the server is down or the host name is wrong.

How to fix it

Work through the causes in this order. It goes from the most common and cheapest to the least.

Fix the connection
  1. Check the credentials

    Open wp-config.php and compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST with the values in your hosting panel. Passwords change after a migration, a host reset or a security rotation.

  2. Check DB_HOST

    Most hosts use localhost, but some use a separate server name such as a hostname shown in the panel. Use the exact value your host gives you.

  3. Make sure the database server is running

    On shared hosting, contact support or restart MySQL from the panel if available. On a VPS, check the service status and restart it if stopped.

  4. Check disk space and quota

    A full disk can crash MySQL. Free space, then restart the service.

  5. Repair the tablesWordPress

    If the admin mentions corrupted tables, enable automatic repair, load the repair page once, then remove the setting.

  6. Restore from a backup if needed

    If the database was deleted or badly damaged, restore the most recent backup from your host or backup plugin.

wp-config.php: database settings to verifyphp
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );
Temporary: enable WordPress table repairphp
define( 'WP_ALLOW_REPAIR', true );
// Then visit: https://example.com/wp-admin/maint/repair.php
// Remove this line when finished.
What to do on your platform
  1. Check wp-config.php

    Edit it through your host's file manager or SFTP and verify the four DB_ values.

  2. Check the siteurl and tables

    In phpMyAdmin, confirm the tables exist (usually prefixed wp_) and the prefix matches $table_prefix in wp-config.php.

  3. Disable plugins if the problem started after an update

    Rename the wp-content/plugins folder to test. Heavy plugins can overload the database.

How to confirm it's fixed

After the fix
  • The home page and a landing page load normally.
  • You can log in to the admin area.
  • Submit a test form and check that the entry appears and the email arrives.
  • Run a test checkout up to the payment step.
  • Check that your tracking tags fire on the page.
  • Clear any page cache so visitors do not get a stale error page.

How to prevent it happening again

Prevention
  • Keep daily backups of files and the database, and test a restore.
  • Record database credentials somewhere safe before changing them.
  • After any migration, verify wp-config.php straight away.
  • Watch disk space and database size.
  • Move to a larger plan if traffic regularly overloads the database.
  • Monitor your key pages and forms so you hear about outages before customers do.
How an unnoticed outage unfolds
  1. 02:10

    Example: the database server stops after the disk fills.

  2. 02:11

    Every page shows the connection error. Ads keep sending traffic.

  3. 08:30

    Someone on the team notices when they open the site.

  4. 09:00

    Space is freed, MySQL restarts and the site recovers.

How FunnelGuard handles this

FunnelGuard detects this issue today. A robot visitor runs your real customer journeys on a schedule, so if a page shows a database error or the journey cannot load, the step fails. Before alerting, FunnelGuard re-checks the failure from a second region, then sends one alert by email, Slack, Teams, WhatsApp, webhook or PagerDuty, with a screenshot and a likely cause.

It tells you the site is down for visitors. It does not repair the database, so you still follow the steps above. The Free plan covers 1 site and 2 journeys with daily checks and no card. Paid plans have a 3-day free trial.

Questions people ask

Why does my website say 'Error establishing a database connection'?

Your site cannot connect to its database. The most common causes are wrong credentials in wp-config.php, a stopped or overloaded database server, a full disk, or corrupted tables.

How do I fix 'Error establishing a database connection' in WordPress?

First verify DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php against your hosting panel. Then confirm the database server is running and has disk space, and repair tables with WP_ALLOW_REPAIR if the admin reports damage.

Can a database connection error happen suddenly with no changes?

Yes. A database server crash, a full disk, a host-side incident or a traffic spike that exhausts connections can all trigger it without any change on your side. Check your host's status page and logs.

Does a database connection error hurt my SEO?

Brief outages usually do little harm, but long or repeated errors can cause search engines to see failing pages and crawl less. The bigger direct cost is lost leads and wasted ad spend.

How do I know if my database is down or just the credentials are wrong?

Try logging in with the same details through phpMyAdmin or the mysql command. 'Access denied' points to wrong credentials, while 'Can't connect' points to the server being down or the wrong host.

Is the WP_ALLOW_REPAIR setting safe to use?

It is safe if you use it briefly. The repair page works without login while the setting is on, so remove the line from wp-config.php once the repair is finished.

How can I get alerted when my site shows a database error?

Use monitoring that loads your pages and journeys on a schedule. FunnelGuard does this with a robot visitor, re-checks failures from a second region and sends one alert with a screenshot and likely cause.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.