Opening your site to find “Error establishing a database connection” is every site owner’s nightmare. It means your WordPress site can no longer talk to your MariaDB or MySQL database. At CODE TOT, we manage enterprise-scale databases, and we’ve found that this error is usually caused by one of three things: wrong credentials, a crashed service, or a “Zombie” database connection.
Professional Insight: Before changing your password in wp-config.php, check your server’s disk space. On RunCloud, if your server reaches 100% disk usage, MariaDB will shut down safely to prevent data corruption, resulting in this error message.
1. The “max_connections” Bottleneck
On high-traffic sites, the error might happen even if your password is correct. This happens when you hit the **max_connections** limit of MySQL. If your server is set to 151 connections and you have 152 simultaneous visitors, the “last” visitor gets the connection error. You can increase this in your MariaDB settings:
# In /etc/mysql/mariadb.conf.d/50-server.cnf
max_connections = 5002. Is MariaDB actually running?
SSH into your server and check the service status. If it’s `inactive` or `failed`, try to restart it. If it fails to restart, check the logs (usually at `/var/log/mysql/error.log`).
# Check status
sudo systemctl status mariadb
# Restart if needed
sudo systemctl restart mariadb3. The skip-name-resolve Trick
If your database is slow to connect or intermittently fails, it might be due to a DNS lookup issue within MySQL. Adding skip-name-resolve to your configuration tells MariaDB to only use IP addresses for authentication, which can drastically speed up connections and reduce timeouts:
# Add to [mysqld] section
skip-name-resolve4. Repairing Corrupted Tables
If you can access `wp-admin` but see the error on the frontend, you may have corrupted tables (common after a server crash). Add this to `wp-config.php` and visit `yoursite.com/wp-admin/maint/repair.php`:
define( 'WP_ALLOW_REPAIR', true );Conclusion
A database connection error is a failure in the site’s most critical conversation. By checking your credentials, verifying disk space, and optimizing connection limits, you can ensure a stable bridge between your content and your users. For advanced database tuning or MariaDB clustering, reach out to our Database Performance Team.
