AI Audit Schedule a Call
Updates & Care November 21, 2026

Error Establishing a Database Connection: How to Fix It

Error Establishing a Database Connection: How to Fix It
On this page
  1. How do you fix error establishing a database connection fast?
  2. What does error establishing a database connection mean?
  3. How do you check the wp-config database credentials?
  4. Is the database server down or over its limit?
  5. How do you repair the WordPress database?
  6. Could a hack cause this error?
  7. What the evidence does not tell you
  8. When should you call your host or get help?
  9. Frequently asked questions

Error establishing a database connection means WordPress could not reach or log in to its database, so it cannot build any page. According to the WordPress developer documentation, it is usually caused by an error in your wp-config.php file. A database that has been shut down or a server that is down are the other main causes. This article walks through the fix in order.

Most of these fixes are quick, but a site that is down costs you customers while you troubleshoot. If you would rather have someone handle it, Atgler’s emergency dev hours cover urgent WordPress breakages without a retainer.

How do you fix error establishing a database connection fast?

Most cases are solved by one of the first three steps below. Work through them in order:

  1. Back up first. Copy your files and, if you can reach it, the database. Kinsta’s documentation (vendor-reported) says to back up before you start.
  2. Check the credentials in wp-config.php. Confirm the database name, username, password and host match what your host shows.
  3. Check the database server. Find out whether it is running and whether the database has hit its quota.
  4. Repair the database. Use WP_ALLOW_REPAIR, wp db repair or phpMyAdmin if the tables are corrupted.
  5. Scan for a hack. If the first four checks are clean, the site may be compromised.

Stop as soon as the site loads. Each step below explains what to look for, so you can work through them in this order, and stop as soon as the site loads.

Five-step checklist for fixing the WordPress database connection error
The fix order: credentials first, then host, repair, and compromise.

What does error establishing a database connection mean?

It means WordPress could not complete the connection to its database. WordPress stores your posts, pages, settings and users in the database, so without a connection it has nothing to show.

The error is a symptom, not a single fault. The WordPress developer documentation points first to wp-config.php, then to the host or database server, and then to a possible compromise. Kinsta adds two more causes (vendor-reported): DNS not pointed to the host, and corrupted WordPress core files.

How do you check the wp-config database credentials?

Open wp-config.php in your site’s root folder and check four values: DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. The WordPress documentation says to confirm that the database name, username, password and host in that file are correct.

Compare them with the database details in your hosting account. Kinsta (vendor-reported) says incorrect credentials are common after manual migrations or installs, and recommends comparing the four values with the host’s database access details.

What if the credentials look right?

If they all match, the WordPress documentation suggests resetting your MySQL password manually. If you do, update DB_PASSWORD in wp-config.php to the new value at the same time, or you will create the same error yourself.

Why did it start right after a migration?

A new host usually means a new database name, user, password and sometimes host value. If the old values were copied across, the connection fails. Our guide on migration plugins versus manual migration covers where those mistakes tend to creep in.

A forum anecdote shows how confusing this gets. In one WordPress.org support thread from around December 2025, a user hit this error on a local XAMPP install and could not find wp-config.php. A moderator said the error should not appear during a normal setup, and another reply advised editing the database name, username, password and host in that file. The thread was closed unresolved, and it is one person’s experience, not a pattern.

Is the database server down or over its limit?

If your credentials are correct, the problem may be on the host’s side. The WordPress documentation names two causes: a database that has “met its quota and has been shut down”, and a server that is down. Its advice is to contact your hosting provider to check both.

A connection cap is another host-side possibility. The MySQL 8.4 manual explains that when clients get a “Too many connections” error, all available connections are in use by other clients. The limit is the max_connections system variable, and the server permits one extra connection reserved for accounts with administrative privileges. That page does not mention WordPress, so treat it as one way a limit can show up, not a confirmed cause of your error.

The WordPress documentation does not say what to ask the host. A practical message is: “Is the database server running, has my database hit a quota or connection limit, and can you confirm the database user and password in my account?” Whatever you send, tell them exactly what you already checked.

Table of causes of the database connection error and who fixes each
Credentials are the most likely culprit and the easiest to check.

How do you repair the WordPress database?

If the credentials and the server are fine, corrupted tables are the next suspect. There are three common ways to repair a WordPress database, and all three work on the same underlying tables.

MethodHow it worksWatch out for
WP_ALLOW_REPAIRAdd define( 'WP_ALLOW_REPAIR', true ); to wp-config.php, then open /wp-admin/maint/repair.php on your site.No login is needed while the constant is on. Remove it afterward.
wp db repairWP-CLI runs mysqlcheck with --repair=true, using the credentials in wp-config.php.Needs command-line access. Credentials default to DB_USER and DB_PASSWORD.
phpMyAdminSelect the tables and choose “Repair table”.Back up first. Kinsta (vendor-reported) suggests selecting all tables.

Is it safe to leave WP_ALLOW_REPAIR on?

No. The WordPress documentation says the repair tool is meant for cases where a corrupted database also blocks logins, which is why it works without signing in. It says to enable it only when needed and turn it off once the problem is fixed. Kinsta (vendor-reported) also says to remove the line afterward.

Kinsta describes the “Repair Database” option as faster than “Repair and Optimize”. We could not confirm the exact wording of the repair screen from a primary source, so read what it shows before you click.

Where does repair fit in the official order?

The sources disagree slightly here. The official page does not list repair under this specific error. It appears under other errors (Error 145 and Error 28), where it advises backing up and then running CHECK/REPAIR in phpMyAdmin or asking the host to. Kinsta and many hosts put repair directly in their connection-error path. Repair is a reasonable step after credentials and server checks, but it is not guaranteed to fix this error.

If repair does not help, Kinsta lists reinstalling core files without touching wp-content, and then restoring a backup, as last resorts. Our guide to restoring a WordPress backup and database explains that step.

Could a hack cause this error?

Yes. The WordPress documentation says that if the configuration and hosting checks come back clean, the site may have been hacked. It advises scanning with Sucuri SiteCheck, a commercial security vendor’s tool, and following the “My Site was Hacked” guidance.

At Atgler, we have worked with WordPress for 7 years and have built, managed and maintained more than 600 sites. When a site is infected, we follow one standard procedure whatever the symptom: remove the malware, rebuild core from clean files and patch the vulnerabilities we can identify. We do not promise to prove how a site was hacked. If you suspect a compromise, see our checklist for a hacked WordPress site or our hacked site repair service, which is $149 Standard (48 hr) or $249 Priority (24 hr), flat fee.

What the evidence does not tell you

Some useful answers are not published, so be wary of anyone who sounds certain about them.

  • We found no study or survey on how often this error occurs or what the most common cause is.
  • We found no official WordPress.org figures for host limits such as connection caps, memory or database size quotas. The MySQL manual gives the max_connections rule but no default value.
  • The official page only says to contact your host. It does not say what to ask or when to escalate.
  • Kinsta’s guidance is dated August 13, 2024, and assumes a managed host with its own tools. Other hosts will differ.

When should you call your host or get help?

Call your host if the credentials match your account, you cannot see a quota or server status, or the host’s panel shows the database as unavailable. Kinsta (vendor-reported) also says to contact support if its repair steps fail.

Call a developer if you are not comfortable editing wp-config.php, if repair does not help, or if you suspect a hack. Atgler’s emergency dev hours are $99 per hour with no retainer, so you pay only for the time spent.

To avoid being surprised, uptime monitoring helps. Our website care plans (from $99 a month, month to month) include uptime monitoring and prompt investigation of downtime, plus backups and a short monthly report. In one case we observed, a backup plugin silently disconnected and stopped both backups and downtime alerts, so check that your own alerts still work.

Frequently asked questions

Why did the error appear right after I moved hosts?

Wrong credentials in wp-config.php are the usual suspect. Kinsta (vendor-reported) says incorrect credentials are common after manual migrations or installs, so compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST with the new host’s details.

Does wp db repair need a separate password?

No. According to the WP-CLI handbook, it takes its credentials from wp-config.php, with the user defaulting to DB_USER and the password to DB_PASSWORD.

Should I leave repair mode on after it works?

No. The WordPress documentation says to turn it off once the problem is fixed, because the repair tool needs no login while the constant is on.

Can my host’s quota cause this error?

Yes. The WordPress documentation says a database that has met its quota can be shut down, and it advises contacting your host to check.

What if the error appears on a local XAMPP install?

The same checks apply: the database name, username, password and host in wp-config.php. In a WordPress.org thread, a moderator said the error should not appear during normal setup, and the thread was closed unresolved.

Sources