How do you fix ‘Error Establishing a Database Connection’ in WordPress?

Begin with a complete backup of any database files or exports still available and record when the message started. Check the hosting status and confirm that the database service is running. If several sites using the same server fail together, contact the provider before changing each WordPress configuration.
Compare the four database settings in wp-config.php with the active hosting account: name, user, password, and host. Include prefixes and custom ports exactly. Resetting a database password requires updating the WordPress configuration immediately, and the database user must still have privileges on the correct database.
Test the credentials through the hosting database tool or ask support to verify them. Check storage and connection quotas. When the server reports damaged tables, use the host’s repair feature or WordPress repair mode only after creating a backup and understanding that its repair endpoint requires careful temporary exposure.
If the error began during a migration, confirm that the domain points to the intended server and that the uploaded wp-config.php belongs to that environment. Restore the last working configuration or database when necessary. After access returns, test dashboard saves, comments or form writes, scheduled jobs, and normal traffic for recurring connection failures.