WordPress: Error Establishing a Database Connection
WordPress can’t connect to its MySQL/MariaDB database with the credentials in wp-config.php, or the database server is down.
Meaning
Every WordPress page needs the database. This error appears when the DB host is unreachable, credentials are wrong, the database doesn’t exist, or the server has run out of connections or memory.
Common causes
- Wrong
DB_NAME,DB_USER,DB_PASSWORDorDB_HOSTin wp-config.php - MySQL/MariaDB service stopped or crashed (often out of memory)
- Database user lacks privileges on the database
- Too many connections / host resource limits on shared hosting
- Corrupted tables (admin may show “One or more database tables are unavailable”)
- Site migrated without updating credentials or host
⚡ Quick fix
- Verify the four DB constants in wp-config.php against your hosting panel
- Restart MySQL/MariaDB and check its error log
- Test the credentials with a tiny PHP script or the mysql CLI
- Repair tables: add
define('WP_ALLOW_REPAIR', true);and visit /wp-admin/maint/repair.php (remove afterwards)
Detailed fix by platform
WordPress
- wp-config.php values to check:php
define('DB_NAME', 'wp_database'); define('DB_USER', 'wp_user'); define('DB_PASSWORD', 'correct-password'); define('DB_HOST', 'localhost'); // some hosts need 127.0.0.1, a socket, or a remote hostname
MySQL
sudo systemctl status mysqlandsudo journalctl -u mysql. If it was OOM-killed, reduceinnodb_buffer_pool_sizeor add swap.
Code examples
Test credentials from the server
bash
mysql -h localhost -u wp_user -p wp_database -e "SELECT 1;"How to diagnose
- Credentials — Do wp-config values match?
- Service — Is the DB server running?
- Privileges — Does the user have access?
- Resources — Memory/connection limits hit?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026