Fix WordPress 'Error Establishing a Database Connection'

Updated: 11/29/2025

You type in your URL, expecting to see your homepage, but you are greeted by a blank white screen with bold black text: 'Error establishing a database connection'. This is the 'Blue Screen of Death' for websites. It means your WordPress PHP files are working fine, but they cannot talk to the MySQL database where your content lives. This is usually caused by a wrong password in your config file or a crashed server service.

Method 1: Check wp-config.php Credentials

This file holds the keys to your database. If you changed your hosting password recently, this file is now wrong.

Step 1: Access File Manager

Log into your cPanel or use an FTP client (FileZilla). Go to public_html.

Step 2: Edit Config

Right-click wp-config.php and select Edit. Look for:

define('DB_PASSWORD', 'your_password_here');

Ensure this password matches exactly the user password in your MySQL Databases section. If you aren't sure, create a new database user password and update this file.

Method 2: Repair the Database

WordPress has a built-in repair tool that is hidden by default.

Step 1: Enable Repair Mode

Add this line to your wp-config.php file:

define('WP_ALLOW_REPAIR', true);

Step 2: Run Script

Visit yourdomain.com/wp-admin/maint/repair.php. Click 'Repair Database'. Once finished, remove the line from your config file immediately for security.

Method 3: Restart MySQL Service (VPS/Dedicated)

If you run your own server (DigitalOcean/Linode), the SQL service might have crashed due to low RAM.

  • SSH into your server.
  • Run: sudo service mysql restart (or mariadb).
  • If it says 'Failed', your server is out of memory. You need to upgrade your RAM or add swap space.