Errors 3 min read

Fix “Error Establishing a Database Connection” in WordPress

This error means WordPress can't talk to its database. Usually it's wrong credentials, a crashed database server or a corrupted table. Here's how to diagnose and fix it quickly.

On this page

Key takeaways

  • This error means WordPress can’t connect to its MySQL/MariaDB database.
  • Most common causes: wrong credentials in wp-config.php (often after a migration), a database server that’s down or overloaded, or a corrupted database.
  • Check credentials first, then the database server, then repair tables.

“Error establishing a database connection” replaces your entire site with one line of text. Since every page in WordPress comes from the database, nothing works until it’s fixed. Fortunately, the causes are limited and the checks are quick.

Step 1: is it the whole site or just the admin?#

  • Both front end and admin: credentials or server problem.
  • Admin shows “One or more database tables are unavailable”: tables need repair (step 4).

Step 2: check wp-config.php credentials#

define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
  • Compare each value with your hosting panel’s MySQL Databases section (names often include a prefix like user_).
  • Confirm the user is assigned to the database with all privileges.
  • Reset the database user’s password in the panel and update wp-config.php if unsure.
  • DB_HOST isn’t always localhost — some hosts use a hostname or 127.0.0.1:3306; check their documentation.

You can test credentials with a tiny PHP file (delete it afterwards):

<?php
$link = mysqli_connect( 'localhost', 'database_user', 'password', 'database_name' );
echo $link ? 'Connected' : 'Error: ' . mysqli_connect_error();

Step 3: is the database server up?#

  • Check your host’s status page or ask support.
  • Try opening phpMyAdmin — if it can’t connect either, the server is down.
  • Traffic spikes, bots or heavy plugins can exhaust database connections on shared hosting. Caching and a CDN reduce load; upgrading hosting may be necessary.
  • Check whether your hosting account exceeded storage limits — a full disk can stop MySQL.

Need a hand with this?

Get a quick, honest review of your website’s SEO.

Chat on WhatsApp

Step 4: repair corrupted tables#

  1. Add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php.
  2. Visit yourdomain.com/wp-admin/maint/repair.php and click “Repair Database”.
  3. Remove the line afterwards — the repair page doesn’t require login.

Alternatively, use phpMyAdmin’s “Repair table” or wp db repair.

Step 5: other causes#

  • After a migration: database not imported, or imported into a different database.
  • Wrong table prefix: $table_prefix in wp-config.php must match the tables (e.g. wp_ vs wpx7_).
  • Hacked site: attackers sometimes change credentials or corrupt data — restore a clean backup.
  • Wrong site URL in the database: causes redirects, not this error, but check wp_options siteurl/home after migrations.

Prevent it#

Database connection FAQ#

Did I lose my content?#

Usually not. The content is still in the database; WordPress just can’t reach it.

Why does the error come and go?#

Intermittent errors usually mean the database server is overloaded or hitting connection limits.

Can a plugin cause this?#

Indirectly — by overloading the database with heavy queries. Query Monitor helps identify them once the site is back.

Found this useful? Share it

Join the discussion

Your email address will not be published. Required fields are marked *

Security code image. If you cannot read it, press refresh or contact me on WhatsApp.