Error establishing a database connection
Error establishing a database connection WordPress Database Connection Error Error
What This Error Means
This error indicates that your WordPress website is unable to connect to its database server. WordPress stores all of its content, settings, and user data in a database, so a failed connection prevents the website from functioning correctly. This usually results in a blank page or an error message being displayed to visitors.
Common Causes
- Incorrect database credentials (hostname, username, password, database name) in the `wp-config.php` file.
- The database server is down or unreachable due to server maintenance, overload, or network issues.
- Database server is running but not accepting connections from the WordPress server (firewall or configuration issue).
- Corrupted database files or tables.
- Database server has reached its connection limit.
How to Fix It (For Users)
- 1 Contact your web hosting provider to ensure the database server is online and functioning correctly. Ask them to check for any server-side issues.
- 2 If you recently changed your database password, update it in the `wp-config.php` file via FTP or your hosting control panel's file manager. Double-check for typos.
- 3 Try clearing your browser cache and cookies, or try accessing the site from a different browser. This is less likely to be the cause, but it's a quick check.
- 4 If you have recently installed or updated a plugin/theme, try deactivating it via FTP by renaming the plugin/theme folder in the `wp-content` directory. Faulty code can sometimes cause database issues.
For Site Owners / Developers
- Verify the database credentials in `wp-config.php` are accurate. Use your hosting control panel (e.g., cPanel, Plesk) to confirm the database name, username, and password.
- Check the database server's status (e.g., using `mysqladmin ping` or similar tools). Restart the database server if necessary.
- Examine the database server's error logs for clues about the connection failure. Common issues include exceeding connection limits or authentication failures.
- Use a database management tool (e.g., phpMyAdmin) to check the database's health. Repair any corrupted tables using the `REPAIR TABLE` command.
- Check your firewall rules to ensure that the WordPress server can connect to the database server on port 3306 (or the appropriate port for your database server).
- Increase the `max_connections` setting in your MySQL/MariaDB configuration file (`my.cnf` or `my.ini`) if the database server is frequently reaching its connection limit. Restart the database server after making changes.
- If using a remote database server, ensure that remote connections are allowed and configured correctly in the database server's configuration.
When It Is NOT Your Fault
This error can occur due to issues beyond your control, such as your hosting provider experiencing a server outage or performing maintenance on the database server. It can also be caused by a DDoS attack overwhelming the database server. In such cases, the only solution is to wait for the hosting provider to resolve the issue or mitigate the attack.
Is the website actually down?
Sometimes the issue is just on your end. Check if the website is down for everyone or just you.
Check Website Status →Recommended Tool to Prevent This Error
Prevent server timeouts and resource exhaustion with scalable cloud infrastructure.