Key takeaways
- This error means WordPress can’t connect to its MySQL/MariaDB database.
- Most common causes: wrong credentials in wp-config.php (often after a migration), a database server that’s down or overloaded, or a corrupted database.
- Check credentials first, then the database server, then repair tables.
“Error establishing a database connection” replaces your entire site with one line of text. Since every page in WordPress comes from the database, nothing works until it’s fixed. Fortunately, the causes are limited and the checks are quick.
Step 1: is it the whole site or just the admin?#
- Both front end and admin: credentials or server problem.
- Admin shows “One or more database tables are unavailable”: tables need repair (step 4).
Step 2: check wp-config.php credentials#
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
- Compare each value with your hosting panel’s MySQL Databases section (names often include a prefix like
user_). - Confirm the user is assigned to the database with all privileges.
- Reset the database user’s password in the panel and update
wp-config.phpif unsure. DB_HOSTisn’t alwayslocalhost— some hosts use a hostname or127.0.0.1:3306; check their documentation.
You can test credentials with a tiny PHP file (delete it afterwards):
<?php
$link = mysqli_connect( 'localhost', 'database_user', 'password', 'database_name' );
echo $link ? 'Connected' : 'Error: ' . mysqli_connect_error();
Step 3: is the database server up?#
- Check your host’s status page or ask support.
- Try opening phpMyAdmin — if it can’t connect either, the server is down.
- Traffic spikes, bots or heavy plugins can exhaust database connections on shared hosting. Caching and a CDN reduce load; upgrading hosting may be necessary.
- Check whether your hosting account exceeded storage limits — a full disk can stop MySQL.
Need a hand with this?
Get a quick, honest review of your website’s SEO.
Step 4: repair corrupted tables#
- Add
define( 'WP_ALLOW_REPAIR', true );towp-config.php. - Visit
yourdomain.com/wp-admin/maint/repair.phpand click “Repair Database”. - Remove the line afterwards — the repair page doesn’t require login.
Alternatively, use phpMyAdmin’s “Repair table” or wp db repair.
Step 5: other causes#
- After a migration: database not imported, or imported into a different database.
- Wrong table prefix:
$table_prefixinwp-config.phpmust match the tables (e.g.wp_vswpx7_). - Hacked site: attackers sometimes change credentials or corrupt data — restore a clean backup.
- Wrong site URL in the database: causes redirects, not this error, but check
wp_optionssiteurl/home after migrations.
Prevent it#
- Reliable hosting with adequate resources — see hosting types.
- Page caching and a CDN to reduce database load.
- Uptime monitoring with alerts.
- Regular backups and database maintenance.
Database connection FAQ#
Did I lose my content?#
Usually not. The content is still in the database; WordPress just can’t reach it.
Why does the error come and go?#
Intermittent errors usually mean the database server is overloaded or hitting connection limits.
Can a plugin cause this?#
Indirectly — by overloading the database with heavy queries. Query Monitor helps identify them once the site is back.