WordPress "Error Establishing a Database Connection" means WordPress cannot connect to MySQL. The site is completely down until this is resolved.
Step 1 — Check MySQL is Running
sudo systemctl status mysql
# If not running:
sudo systemctl start mysql
sudo journalctl -u mysql -n 50 # Check why it stopped
Step 2 — Test Database Credentials
# Get credentials from wp-config.php
grep "DB_" /var/www/html/wp-config.php
# Test connection manually
mysql -u DB_USER -p'DB_PASSWORD' -h DB_HOST DB_NAME
# If this fails — credentials are wrong
Step 3 — Fix Wrong Credentials
# Log in as root and reset password
sudo mysql -u root
ALTER USER 'wpuser'@'localhost' IDENTIFIED BY 'NewPassword';
FLUSH PRIVILEGES;
# Update wp-config.php
define('DB_PASSWORD', 'NewPassword');
Step 4 — Fix MySQL InnoDB Corruption
# Check for crashed tables
mysqlcheck --all-databases -u root -p
# Repair specific table
mysqlcheck -u root -p --repair dbname wp_options
# Force InnoDB recovery (last resort)
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
innodb_force_recovery = 1
sudo systemctl restart mysql
# Export data, then remove innodb_force_recovery and reimport
Step 5 — Fix Too Many Connections
# Connect as root (reserved connection)
mysql -u root -p
SET GLOBAL max_connections = 300;
SHOW STATUS LIKE 'Threads_connected';
Step 6 — Fix MySQL Disk Full
# MySQL stops if disk is full
df -h
# Free disk space (see disk full guide)
# Then restart MySQL
sudo systemctl start mysql
Conclusion
Database connection errors need immediate diagnosis. Our team provides emergency database recovery with 15-minute response time.
Comments