Lorixen.
EN

'Error Establishing a Database Connection' in WordPress: What to Check, in Order

Short answer: WordPress shows "Error establishing a database connection" when PHP cannot log in to MySQL or MariaDB, or logs in and finds the data unusable. Check in this order: whether the host's database server is down, whether the four database values in wp-config.php still match the database, whether that user still has privileges, whether the server has run out of connections, and only then whether tables are damaged. Most cases are a host outage or a changed password, and neither needs any change to WordPress itself. Do not reinstall WordPress or restore an old backup until you know which of these it is.

First, take a careful look at what is broken

A few minutes of observation saves hours of guessing. Open the site in a private window and on your phone's mobile data, then answer three questions.

  • Is it every page or only /wp-admin? If the front end loads but the dashboard shows "One or more database tables are unavailable", you are probably looking at damaged tables, not a login failure.
  • Did it start after a change? A host migration, a password reset in the control panel, a new caching plugin or a PHP version switch narrows the search immediately.
  • Is it constant or on and off? An error that comes and goes during busy hours points to connection limits or an overloaded server rather than wrong credentials.

Write down the time you first saw it. Your host's support team will ask for it.

Step 1: Check the host's status page

Shared hosting usually runs the database on a separate machine from the web server. If that machine is down, every site on it shows the same message, and nothing you edit will help.

  1. Open your host's status or network page and look for incidents affecting MySQL, databases or your server name.
  2. Log in to the control panel and open phpMyAdmin. If phpMyAdmin also fails to connect, the database service is the problem.
  3. If both are down, open a ticket, quote the time and leave the files alone.

Step 2: Compare wp-config.php with the real database details

If the database service works, compare the connection settings. Open wp-config.php in the site root with the host's file manager or SFTP and find these lines:

define( 'DB_NAME', 'example_wp123' );
define( 'DB_USER', 'example_user' );
define( 'DB_PASSWORD', '...' );
define( 'DB_HOST', 'localhost' );

Then check each value against the database section of your control panel.

Setting What to compare Common mistake
DB_NAME Exact database name, including any account prefix Prefix missing after a migration
DB_USER Database user, not your hosting login Using the control panel username
DB_PASSWORD Current database user password Password was reset in the panel
DB_HOST Hostname given by the host Left as localhost when the host uses a separate server name or port

The meaning of each constant is documented in the wp-config.php reference. If you are unsure about the password, set a new one for the database user in the control panel and paste the same value into wp-config.php. Watch out for stray spaces and smart quotes if you copy from an email. Save a copy of the original file first so you can undo the edit.

Step 3: Confirm the user still has privileges

A user can exist with the right password but no rights on the database, for example after a database was recreated from a backup. In the control panel's database section, check that the user is assigned to the database with all privileges. In phpMyAdmin, log in with the exact user and password from wp-config.php: if the login succeeds but you cannot see the WordPress tables, the assignment is missing.

Step 4: Rule out too many connections

When the error appears only at busy times, the database may be refusing new connections because it has reached its limit. Shared plans often cap concurrent connections per account. Typical triggers:

  • a traffic spike from a newsletter or social post
  • bots hammering search pages, login forms or xmlrpc.php
  • a plugin running heavy queries on every page view
  • a cron task that starts many processes at once

Ask your host whether the account hit "max connections" or "max user connections" at the times you noted. Short-term fixes are page caching, blocking abusive bots at the firewall and disabling the plugin that runs the expensive queries. If the limit is simply too low for your traffic, a plan with dedicated resources is the honest answer.

Step 5: Repair damaged tables, carefully

If the message mentions unavailable tables, or phpMyAdmin marks some tables as "in use" or crashed, WordPress has a built-in repair screen.

  1. Take a database export from phpMyAdmin first, even if it is partial.
  2. Add this line to wp-config.php above the "stop editing" comment: define( 'WP_ALLOW_REPAIR', true );
  3. Visit yourdomain.com/wp-admin/maint/repair.php and choose "Repair Database".
  4. When it finishes, remove that line again. The repair page does not require a login while it is enabled, so anyone could run it.

If the repair screen reports tables it cannot fix, stop and involve the host, who can restore that table from its own backups.

What not to do

Panic leads to steps that make recovery harder.

  • Do not reinstall WordPress. The database is the problem, not the core files, and a fresh install can overwrite wp-config.php.
  • Do not restore last month's full backup before you know the cause. You may lose orders, form entries or posts written since.
  • Do not create a new database and point the site at it. The site will load an empty installer, and visitors or bots might complete it.
  • Do not post your wp-config.php in a forum without removing the password and salts.

What to tell your host

A clear ticket gets a faster answer. Include:

  • the domain and the exact error text
  • when it started and whether it is constant or intermittent
  • what you checked (status page, phpMyAdmin login, credentials match)
  • any change made shortly before, such as a migration or password reset
  • a request to check database server health, connection limits and recent error logs for your account

FAQ

Why does the admin area say tables are unavailable when the home page works?

WordPress runs an extra check in the dashboard. When some tables are damaged it reports that instead of failing completely, which usually means a repair, not a credentials problem.

Can a plugin cause this error?

Indirectly. A plugin that runs slow queries can use up connections or overload the database, which then refuses new logins.

Is it safe to leave WP_ALLOW_REPAIR enabled?

No. The repair page works without logging in, so remove the line as soon as you are done.

Do I lose content when this error appears?

Normally not. The content stays in the database. The site simply cannot read it until the connection or the tables are fixed.

Should the checks point to something deeper than a login mismatch, send us the details and we can look at the database and hosting setup with you.

Sources

WhatsAppBook a call