Database connection error

Also searched as: connection refused database · database down

Updated 11 October 2026

Short answer

Your site's code is running, but it can't talk to the database where your content, users and orders live. There are four usual causes: the database server is stopped, the connection details (host, port, username, password, database name) are wrong, a firewall is blocking the connection, or the database is full or overloaded. "Connection refused" specifically means nothing is listening at that address, so the database is down or the address is wrong.

What's the problem

Pages show "Database connection error", "Connection refused", "Could not connect to database", or a 500 error. Often the whole site is affected at once.

Why it happens

  • The database server stopped: it crashed, ran out of memory, or was restarted and didn't come back.
  • Connection details changed: a password was rotated, the database moved to a new host, or an environment variable is missing on the live server.
  • A firewall or network rule blocks the app from reaching the database, common with cloud databases that only allow listed IP addresses.
  • The disk is full, so the database can't run. See disk full.
  • All connections are used up. See too many connections.

How to fix it

  1. Check the database is running. In your hosting or cloud dashboard, or on a server: systemctl status mysql (or postgresql).
  2. Check the connection details the live app uses (host, port, user, password, database name) against the database's actual settings.
  3. Check the database's network rules allow your app server's IP address.
  4. Check disk space and memory on the database server.
  5. Read the database's own error log for why it stopped or refused the connection.
  6. If you use managed hosting, check the provider's status page and contact support with the exact error.

What Preventionlabs checks

One click runs the full report on your domain. For this problem it shows whether your site loads, how fast, and where its redirects go; uptime checked every 5 minutes, with an email when the site goes down and when it is back. With Cloudflare connected, it also shows which pages returned server errors (5xx) to visitors, and when; recent deploys and account changes, with their times. It can't connect to your database, so the database error itself is in your host's or database provider's logs.

Run your free report

Your first report is free, no card needed. Then A$50 a month, up to 10 domains. Read-only: it never changes anything.

Sources

  1. MySQL: Can't connect to [local] MySQL serverofficial docsThe error (2002) Can't connect to ... normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server.
  2. MySQL: Can't connect to [local] MySQL serverofficial docsYou should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.
← All of Database