What the message looks like
[29-Nov-2026 09:14:02 UTC] WordPress database error Can't connect to MySQL server on 'localhost' (111) for query SELECT option_value FROM wp_options WHERE option_name = 'siteurl' LIMIT 1 made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php')Common causes
- Wrong values for
DB_NAME,DB_USER,DB_PASSWORDorDB_HOSTinwp-config.php, for example after a migration or password change. - MariaDB/MySQL is stopped, has crashed or was killed by the OOM killer.
- Too many simultaneous connections (
max_connections) or a full disk on the database server. - The database user has no privileges on the database, or the host grant does not match.
- Damaged tables or files, or an update that left the database half-done.
Check
- Is the database service running?
systemctl status mariadb - Does login work with the values from wp-config.php?
mysql -u DBUSER -p -h localhost DBNAME -e 'SELECT 1;' - Which credentials does WordPress use (without password)?
grep -E "DB_(NAME|USER|HOST)" /var/www/html/wp-config.php - Check the database from WordPress, plus disk space
wp db check --path=/var/www/html; df -h /var/lib/mysql
Fix
- Start the service:
systemctl restart mariadb, then look for the cause in the journal (journalctl -u mariadb -n 50 --no-pager). - Compare
DB_NAME,DB_USER,DB_PASSWORDandDB_HOSTinwp-config.phpwith the real values; for a server on another host or port setDB_HOSTashost:port. - Check or reset privileges, for example
GRANT ALL ON dbname.* TO 'dbuser'@'localhost';. - Under overload check
max_connectionsand RAM; on a full disk free up space. - For damaged tables add
define('WP_ALLOW_REPAIR', true);towp-config.php, open/wp-admin/maint/repair.phpand remove the line afterwards. - If the cause stays unclear, restore a backup.
Typical scenario
A WordPress site on a small VPS suddenly shows “Error establishing a database connection” during the night. The journal contains “Out of memory: Killed process (mariadbd)”: the OOM killer ended the database because a backup job and a crawler used RAM at the same time. After systemctl start mariadb the site works again; swap and smaller PHP-FPM pools help in the long run.
FAQ
Does the error affect only the front end or /wp-admin too?
Often both. If only /wp-admin shows “One or more database tables are unavailable”, tables are damaged. WordPress's repair tool then helps.
Is the database lost after this error?
Normally not. The error only says the connection fails. Still, back up the data first (mysqldump) before repairing or changing privileges.
The error appears only briefly and irregularly. Why?
Typical causes are load spikes with exhausted connections, a database service restarting briefly, or a full disk. Look in the database log and for Too many connections at the time of the error.
How do I find errors in wp-config.php without exposing the password?
Test the same values with the command-line client: mysql -u USER -p -h HOST DBNAME. If it reports Access denied, user, password or privileges are wrong; if it reports a connection error, host, port or service is wrong.