Checked
2026-11-14
/ Database connection

Error establishing a database connection. Check these first.

WordPress loaded, asked its database for the page, and got no answer. On your own server the database has usually stopped, often because memory or disk ran out. Less often the login details in wp-config.php are wrong.

Is the database running?

Log in to the server and ask:

systemctl status mariadb    # or mysql

If it says inactive or failed, that is the cause. Before you start it again, find out why it stopped, or it will stop again tonight.

Why it stopped

Once you know the cause and have dealt with it, systemctl start mariadb, and check that it stays up for a few minutes.

  • Memory: dmesg -T | grep -i -E 'killed process|out of memory' shows whether the kernel killed mysqld to free memory. On a small VPS this is the most common cause, often after a traffic spike or a bot crawl.
  • Disk: df -h. With a full disk the database cannot write, and it stops or refuses to start.
  • Its own log: journalctl -u mariadb -n 100, or /var/log/mysql/error.log, names a crash, a damaged table or a config error after an update.

If the database runs, check wp-config.php

WordPress reads four values from wp-config.php: DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Try them by hand:

mysql -u DB_USER -p -h DB_HOST DB_NAME

If that login fails, the values or the database user's rights are wrong. That happens after a move to a new server, a password change, or a host that changed the database address. If it works and WordPress still cannot connect, try DB_HOST as 127.0.0.1 instead of localhost, or the other way round: PHP reads localhost as the local socket and 127.0.0.1 as a network port, and a server may listen on only one of them.

If a table is damaged

When WordPress says one or more tables need repair, it has a tool for that. Add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php, open /wp-admin/maint/repair.php, and remove the line as soon as it is done: while it is on, the page works without a login.

With WP-CLI, wp db check checks every table and reports problems.

What not to do

  • Do not reinstall WordPress. The files are rarely the problem, and the content lives in the database.
  • Do not run a repair on a database whose disk is full. Free space first.
  • Do not copy the files in /var/lib/mysql while the database runs and call it a backup. Use mysqldump or your host's backup.

When to stop and hand it over

Stop if the database will not start, if its log mentions corruption or InnoDB recovery, or if there is no recent backup. A wrong step on a damaged database can lose data that is still there now. Our Server Rescue is one incident at a fixed $69, with a same-day start listed at $109, and nothing to pay if we cannot fix it. Read-only checks come first, and no destructive step runs without a copy in front of it.

/ Questions

Questions people ask

Is my content gone?
Almost never. The message means WordPress cannot reach the database, not that the database is empty. Do not reinstall anything until you know why.
Why does it happen at night or after a traffic spike?
On a small server a burst of visitors or bots uses up the memory, and the kernel stops the biggest process, which is often the database. dmesg shows when it happened.
Can a hacked site cause it?
It can, for example when an attacker changed the database password or filled the disk. If memory, disk and config all check out, read the hacked-site guide next.
What does fixing it cost?
With us, Server Rescue at $69 for the incident, or $109 for a same-day start. If we cannot fix it, you pay nothing.
/ Sources

Where each statement comes from

Checked against the sources on .

More server help