IT bugsolutions

Database connection error

Error establishing a database connection: causes and fix

The short answer

The site is running; the link to its database is broken. That is good news: your posts, pages and orders are usually still stored safely and just cannot be reached right now.

Get it fixed
  • Backup before every change
  • Fixed price before we start
  • Remote, anywhere in the world
  • Free first diagnosis

MySQL and MariaDB report this with codes that narrow it down fast. 2002 means the server could not be reached, 1045 means the login was refused, 1049 means the database name does not exist, and 1040 means too many connections. Which one you get tells us whether to look at the credentials, the host, or the server itself. Do not reinstall anything yet; that rarely helps and can overwrite data.

Sound familiar?

How the database connection error shows up

  • The page shows “Error establishing a database connection” on a white background
  • You see “SQLSTATE[HY000] [2002] Connection refused”, “[1045] Access denied” or “Database connection failed”
  • Both the website and the admin area show the error
  • The error started after moving the site, changing a password or a host maintenance window
  • The error comes and goes during busy periods

Causes

What causes "error establishing a database connection"?

Wrong credentials after a change

After a migration or a password reset, the database name, user or password in wp-config.php or .env no longer matches the real database.

Wrong database host

Many hosts do not use “localhost” but a separate hostname, port or socket. A wrong value means the site looks in the wrong place.

Database server down or overloaded

MySQL or MariaDB stopped, crashed because memory ran out, or is too busy to accept new connections.

Connection limit reached

Hosting plans often limit simultaneous database connections. Traffic spikes, bots or code that does not close connections can use them all up.

Corrupt database tables

A crash or full disk can damage tables. WordPress may then fail to connect properly or report that tables need repair.

Storage or quota full

When the disk or database quota is full, the database server may refuse to start or to write, which breaks the connection.

Try it yourself

Fixing a database connection error yourself

If you manage the site, these checks are safe and often find the cause. Do not delete or reinstall anything yet.

  1. 1 Check your host’s status page and email for maintenance or a database incident.
  2. 2 Open wp-config.php or .env and compare the database name, user, password and host with the values shown in your hosting panel. A single wrong character is enough to break the connection.
  3. 3 If you recently changed the database password in the hosting panel, update it in wp-config.php or .env as well.
  4. 4 Try logging in to phpMyAdmin or your host’s database tool with the same details. If that fails too, the credentials or the database server are the problem, not your site.
  5. 5 Check that your hosting account still has free disk space and has not exceeded its database size.
  6. 6 On WordPress, if the admin says tables need repair, add define('WP_ALLOW_REPAIR', true); to wp-config.php, run /wp-admin/maint/repair.php once, and remove the line straight after.
  7. 7 If the error only appears at busy times, ask your host whether you are hitting the maximum number of database connections.

Our approach

How we repair a database connection error

  1. 1

    You let us know

    Use the short form or the chat, and mention any recent move or password change. We reply with the access we need.

  2. 2

    We back up before anything else

    We copy the site files and, where it is reachable, the database, so every change can be undone.

  3. 3

    We find the broken link and quote

    We check the connection settings, the database server and its limits to see exactly why the connection fails, then send a fixed price.

  4. 4

    We restore the connection and report

    With your approval we fix it, test the site and admin area, and send a short report of what was wrong and what we changed.

What we need

What we need from you

  • Login for your hosting control panel, or SSH/SFTP access
  • Access to the database tool (phpMyAdmin or similar), if your host provides one
  • An admin login for your CMS or application, if there is one
  • What changed recently: a move, a new password, a host change or an update

We ask for the least access that does the job. A separate login for us is best, and you can revoke it as soon as we are done.

What we cannot fix

We cannot restart or repair a database server that your host manages and does not give access to, recover data the host has lost without any backup, or fix an outage inside the provider’s data centre. If the database server itself is down at the host, we tell you quickly and help you put the right question to their support.

Price

Price and what happens next

  1. 1

    Free diagnosis

    We find the cause and tell you what is wrong.

  2. 2

    Fixed price

    You get a price and a time estimate. Nothing starts without your yes.

  3. 3

    Fixed and reported

    We repair it, test it and send a short report.

From €295 excl. VAT

Fixed price, agreed before we start

Is it urgent? Say so in the form or in the chat. We start as soon as we can and give you a realistic time estimate with the quote. If priority work costs extra, you see that in the quote before you agree.

Get it fixed

Questions?

Database connection error: frequently asked questions

Written by the IT bugsolutions team · Last updated:

Request

Tell us what is wrong

Answer a few short questions. You get a fixed price before we do anything.

On which platform are you experiencing the problem?