Fixing "error establishing a database connection" in WordPress

How to resolve the WordPress database connection error by verifying credentials in wp-config.php, repairing corrupted tables, checking MySQL server status and restoring from backup.