📞 🇺🇸 +1 361 304 4309 📞 🇮🇳 +91 76769 02281 ✉️ [email protected]
Troubleshooting & Fixes

How to Fix WordPress Error Establishing Database Connection

How to Fix WordPress Error Establishing Database Connection

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.

#wordpress #database #mysql #connection #error
Share this guide:
🛠️ Need Expert Help?

Don't want to do this yourself?

Our certified engineers implement this for you — correctly, securely, and within hours. Available 24/7 with 15-minute emergency response.

  • ✅ 19+ years experience
  • ✅ 60+ certified engineers
  • ✅ 1,600+ servers managed
  • ✅ 40+ countries served
  • ✅ Plans from $49/mo

Get Expert Help — Free Consultation

We respond within 4 hours · No commitment required

Please enter your name and a valid email.

No spam. Privacy Policy

Comments