The “Error establishing database connection” error on WordPress is one of the most common and frustrating problems one can encounter. This error means that WordPress is unable to connect to the site’s database, which can make your site completely inaccessible, including the admin (/wp-admin
).
In this article, we’ll look at the possible causes of this error and detail the best solutions to fix it quickly.
1. What causes the “Establishing database connection” error?
This error can be caused by several factors, including:
🔹 Incorrect credentials – If the login information (database name, user, password, host) in the wp-config.php
file is incorrect.
🔹 Server-side issue – Your hosting provider’s database server may be temporarily down.
🔹 Corrupted Database – A corrupted database can prevent you from connecting.
🔹 Corrupted WordPress Files – A file that is essential for the database connection may be corrupted.
🔹 Too Many Simultaneous Connections – If your site exceeds the connection limits allowed by your hosting provider.
🔹 Malware attack or infection – A hacked site can be affected by this error if the database has been compromised.
2. How to Fix “Establishing Database Connection” Error?
Solution 1: Check Database Credentials in wp-config.php
The wp-config.php file contains the database connection information. If they are incorrect, WordPress will not be able to connect.
- Access your server via FTP (with FileZilla) or via your host’s file manager.
- Open the wp-config.php file located at the root of the site.
- Locate these lines:
define(‘DB_NAME’, ‘nom_de_votre_base’);
define(‘DB_USER’, ‘your_database_user’);
define(‘DB_PASSWORD’, ‘your_database_password’);
define(‘DB_HOST’, ‘localhost’);
Compare this information with the information provided by your hosting provider. If you recently changed your database password, update it here.
Tip: To see the correct information, log into your hosting provider and view your database details in phpMyAdmin or cPanel.
Solution 2: Check if MySQL server is running
If your MySQL server is offline, WordPress will not be able to establish a connection to the database.
- Log in to your web host and navigate to phpMyAdmin.
- Try connecting to your database.
- If you can access it, it means that MySQL is working fine and the problem is with WordPress.
- If you can’t access it, contact your hosting provider to see if the server is down.
Solution 3: Repair the WordPress database
If your database is corrupted, WordPress may have trouble connecting. To attempt a repair:
1 – Add this line to your wp-config.php
file, just before /* That's all, stop editing! Happy publishing. */
:
define(‘WP_ALLOW_REPAIR’, true);
2 – Go to the following address in your browser
https://yoursite.com/wp-admin/maint/repair.php
3 – Click “Repair Database” and let WordPress do the repair.
4 – Once the repair is complete, delete the line added in wp-config.php
to avoid any security risk.
Solution 4: Check for Corrupted WordPress Files
If some WordPress files are corrupted, it may be helpful to replace the core files.
- Download the latest version of WordPress from wordpress.org.
- Unzip the archive and delete the
/wp-content/
folder. - Upload the remaining files to your server via FTP, overwriting the existing files.
- Test your site to see if the error is gone.
Solution 5: Check the .htaccess
A corrupted .htaccess
file can prevent access to the site. Try this:
- Access your server via FTP and find the
.htaccess
file in the root of your site. - Rename it to
.htaccess_old
. - Try reloading your site.
- If the problem is solved, generate a new
.htaccess
by going to Settings > Permalinks and clicking “Save Changes”.
Solution 6: Increase the MySQL connection limit
Some hosting providers limit the number of simultaneous connections to the database. Try increasing this limit by adding this line in wp-config.php
:
define(‘WP_MAX_CONNECTIONS’, 50);
If this doesn’t work, contact your web host to increase this limit.
Solution 7: Contact your web host
If none of the above solutions work, it’s possible that your web host has a technical problem. Explain your situation to them and ask if:
- MySQL server is running properly.
- Your account has exceeded its resource limits.
- Errors have been detected in the server logs.
How to prevent the “Establishing database connection” error?
✅ Perform regular backups – Use UpdraftPlus or All-in-One WP Migration to backup your database and files.
✅ Avoid unreliable plugins or themes – A poorly coded plugin can corrupt the database.
✅ Update WordPress and MySQL – Always keep your site up to date to avoid compatibility errors.
✅ Optimize Database – Use plugins like WP-Optimize to clean and optimize your database.
✅ Choose a reliable hosting provider – Some hosting providers severely limit resources, which can cause this type of error.
Conclusion
The “Establishing database connection” error on WordPress may seem complicated, but it is usually easy to resolve with a methodical approach. By verifying your login credentials, repairing your database, testing the MySQL server, and replacing corrupted files, you can get your site back online quickly.
If the problem persists, don’t hesitate to contact your web host for help.
Is your site still showing this error? Describe your problem and I’ll help you solve it! Contact us here