Fixing “Error Establishing a Database Connection” (Firstserv Guide)

This error means your WordPress site is unable to connect to its database. It is commonly caused by:

  • Incorrect database credentials
  • Database user or permissions issues
  • Corrupted database
  • Temporary server or database problems

Follow the steps below to identify and resolve the issue.


1. Check Database Details in wp-config.php

Start by verifying your database connection settings.

Steps:

  1. Log in to cPanel
  2. Open File Manager
  3. Navigate to your WordPress directory (usually /public_html/)
  4. Open the wp-config.php file

Look for the following lines:

 
 
 
 
 
 
PHP
 
 
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_user');
define('DB_PASSWORD', 'your_database_password');
define('DB_HOST', 'localhost');
 
 

Check the following values:

  • DB_NAME – Your database name
  • DB_USER – The database username
  • DB_PASSWORD – The password for that user
  • DB_HOST – Usually localhost

2. Verify Database and User in cPanel

Next, confirm that these details match your actual MySQL configuration.

Steps:

  1. In cPanel, go to MySQL Databases
  2. Under Current Databases, check:
    • The database name exists
  3. Confirm:
    • The correct user is assigned to that database

✅ If anything doesn’t match:

  • Update the wp-config.php file with the correct details

3. Reset the Database User Password

If credentials appear correct but the error persists, the password may be incorrect.

Steps:

  1. In cPanel → MySQL Databases
  2. Locate your database user under Current Users
  3. Click Change Password
  4. Set a new strong password

Then update your wp-config.php:

 
 
 
 
 
 
PHP
 
 
define('DB_PASSWORD', 'new_password_here');
 
 

Save the file and retry your website.


4. Check User Permissions

The database user must have the correct permissions to access and modify the database.

Steps:

  1. In cPanel → MySQL Databases
  2. Scroll to Add User to Database
  3. Select the correct:
    • User
    • Database
  4. Click Add
  5. On the next screen, select All Privileges
  6. Click Make Changes

✅ This ensures the user has full access required by WordPress.


5. Additional Checks (If Issue Persists)

If the problem continues, consider:

  • Database corruption – attempt a repair via phpMyAdmin
  • Server issues – temporary database downtime
  • Incorrect DB_HOST – some advanced setups use a different hostname

Summary

To resolve database connection errors:

  1. Verify credentials in wp-config.php
  2. Confirm database and user settings in cPanel
  3. Reset the database password if needed
  4. Ensure the user has full database permissions

If you’re unable to resolve the issue after these steps, the Firstserv support team can help investigate and restore your connection quickly.

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to install the Wordpress Litespeed cache plugin

  LiteSpeed Cache – What It Is and How It Helps If you’re running a WordPress website and...

How to disable the WordPress CRON job and set it up in cPanel

  Optimising WordPress Cron (wp-cron) – Firstserv WordPress does not...

Fixing WordPress mixed content issues

  Fixing Mixed Content Warnings When you visit a website using https://, your browser expects...

How to optimise your WordPress site

Optimising Your WordPress Website (Firstserv Guide) WordPress is a...

Configuring Redis Object Caching using Litespeed Cache

Object Caching and Redis (Firstserv Guide) What is Object Caching? Object caching is a...