There was a problem loading the comments.

How to Fix the 'Error Establishing a Database Connection' in WordPress

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Quick answer: Error establishing a database connection means WordPress cannot reach its database. Check the credentials in wp-config.php (a changed password is the usual cause), confirm the database service is running, repair a corrupted database with WP_ALLOW_REPAIR, and test the login in phpMyAdmin.

"Error establishing a database connection" means WordPress loaded but could not talk to its database. The page is otherwise blank. In almost every case it is one of four causes, and you can work through them in a few minutes.

1. Check the database credentials in wp-config.php

Open wp-config.php in the site root and confirm these four values match a real database and user:

define('DB_NAME', 'your_database');
define('DB_USER', 'your_user');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');

The most common trigger is a recently changed database password that was not updated here. On most shared and cPanel setups DB_HOST is localhost; use a different value only if your host specifies one.

2. Confirm the database server is running

If credentials are correct, the database service itself may be down or overloaded, often after a traffic spike exhausted memory. On a VPS, restart the service and check its status:

systemctl status mysql     # or mariadb
systemctl restart mysql

If it keeps stopping, the server likely needs more memory or query tuning rather than a repeated restart.

3. Repair a corrupted database

If the service is up and credentials are right, a table may be corrupted. Add this line to wp-config.php temporarily:

define('WP_ALLOW_REPAIR', true);

Visit yourdomain.com/wp-admin/maint/repair.php, run the repair, then remove the line so the tool is not left publicly accessible.

4. Test the credentials directly

Still failing? Log in to phpMyAdmin with the same username and password from wp-config.php. If that login also fails, the user or password is wrong; recreate the user and grant it access to the database.

Frequently asked questions

What is the most common cause?
Database credentials in wp-config.php that no longer match, often after a password change.

How do I repair the database?
Add define('WP_ALLOW_REPAIR', true); to wp-config.php, run the repair tool, then remove the line.

On SoftSys managed WordPress hosting the database is monitored and tuned to avoid the overload that causes this error, and our team will diagnose and fix it for you if it ever appears.


Share via
Did you find this article useful?  

Related Articles

Tags

© Softsys Hosting