A safe, step-by-step troubleshooting guide for WordPress database connection errors.
What the error means
WordPress needs a working MySQL or MariaDB database connection to load posts, settings, and user accounts. This error usually means database credentials are wrong, the database server is unavailable, or the database cannot be reached. Avoid immediately reinstalling WordPress or deleting tables.
1. Take a backup before editing
Back up the database and site files through your hosting panel or backup system when possible. If the site is business-critical, take note of recent changes and the exact time the error began.
2. Confirm the database service is running
Check the hosting status page and database service health. Shared hosting outages, resource limits, and recently migrated servers can interrupt connections. Contact the host if you lack access to service logs.
3. Verify wp-config.php carefully
Look at DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-config.php. Compare them with your hosting account. Do not post these secrets publicly or send screenshots showing passwords. On some hosts DB_HOST is not localhost.
4. Check database-user access
A valid user still needs permission to access the specified database. In your hosting panel, confirm that the correct user is assigned to the database with appropriate privileges.
5. Inspect logs and recent changes
Review PHP logs, database errors, disk-space limits, and plugin or hosting changes. A corrupted configuration after migration is different from a temporarily overloaded database server.
6. Investigate corruption cautiously
If your host confirms damaged tables, create a verified backup first. Use the host database repair tools or administrator assistance. Do not run repair commands blindly on a production database.
7. Test and monitor after recovery
Once the connection works, check the homepage, admin dashboard, forms, checkout (if applicable), and scheduled jobs. Confirm that backups remain functional and investigate the underlying reason for the outage.
When to ask for help
If you cannot verify credentials safely, the database host is unreachable, or your store processes orders, contact the hosting provider or an experienced developer rather than experimenting on a live database.
