Skip to main content

Fix: “Error establishing a database connection” in WordPress (HostBible cPanel)

Fix the WordPress “Error establishing a database connection” on HostBible

C
Written by Christopher Handscomb
Updated over 6 months ago

This guide walks you through the fastest, safest checks to resolve WordPress’s database connection error on a cPanel-based HostBible plan.

Before you start

  • If possible, take a quick backup (cPanel → BackupDownload a Home Directory Backup and Download a MySQL Database Backup).

  • Have your cPanel login handy.


What causes this error?

Most cases are one of the following:

  1. Wrong database name, user, or password in wp-config.php.

  2. Wrong DB host (should be localhost in most cPanel setups).

  3. The database user isn’t assigned to the database or lacks privileges.

  4. Corrupted database tables.

  5. The database server is temporarily overloaded or your account is out of disk/inodes.


Quick triage (1–2 minutes)

  • Open phpMyAdmin (cPanel → phpMyAdmin). If phpMyAdmin loads and you see your DB, MySQL is up. If it doesn’t load or errors, there may be a host-side issue—skip to When to contact HostBible.

  • If you have multiple WordPress sites on the same account and all show the same error, it’s more likely a host-side/database service issue.


Step-by-step fixes (cPanel)

1) Confirm your DB name, user & password in wp-config.php

  1. In cPanel, open File Manager → go to your site’s document root (often public_html or the add-on domain’s folder).

  2. Find and edit wp-config.php (right-click → Edit). Look for these lines:

    define( 'DB_NAME', 'cpanelprefix_wpdbname' ); define( 'DB_USER', 'cpanelprefix_dbuser' ); define( 'DB_PASSWORD', 'your_db_password' ); define( 'DB_HOST', 'localhost' );
  3. In another tab, go to cPanel → MySQL® Databases:

    • Under Current Databases, confirm the exact DB name (including the cPanel prefix).

    • Under Current Users, confirm the DB user (including prefix).

  4. If you’re unsure of the password, reset it:

    • In MySQL® Databases → under Current Users, click Change Password for the DB user (use a strong new password), then update the same password in wp-config.php. Save.

Tip: DB names and users in cPanel always include your account prefix, e.g., user1_wp123. They must match exactly in wp-config.php.


2) Make sure the user is assigned to the database (with privileges)

  1. cPanel → MySQL® Databases.

  2. In Add User to Database, pick your DB user and DB nameAdd.

  3. On the privileges screen, tick ALL PRIVILEGESMake Changes.


3) Confirm the database host

  • In most cPanel environments, DB_HOST should be localhost.

  • If you connected your WordPress site to a remote database or your provider gave a different host name (e.g., mysql.example.com), use that value exactly.


4) Check & repair the database (two easy options)

Option A — cPanel’s built-in checker

  1. cPanel → MySQL® Databases.

  2. Under Modify Databases, select your database and click Check Database.

  3. If issues are found, select the same DB and click Repair Database.

Option B — phpMyAdmin repair

  1. cPanel → phpMyAdmin → click your database name on the left.

  2. Tick Check all tables at the bottom.

  3. In the With selected: dropdown, choose Repair table.


5) Use WordPress’s built-in repair tool (safe & quick)

  1. Edit wp-config.php and add this line just above the comment that says “That’s all, stop editing!”:

    define( 'WP_ALLOW_REPAIR', true );
  2. Visit: https://yourdomain.com/wp-admin/maint/repair.php
    Click Repair Database (or Repair and Optimize).

  3. Important: Remove the WP_ALLOW_REPAIR line from wp-config.php after you’re done.


6) Optional: direct connection test (helps pinpoint credential issues)

Create a temporary file named testdb.php in your site’s root and paste:

<?php $mysqli = @new mysqli('localhost', 'DB_USER_HERE', 'DB_PASS_HERE', 'DB_NAME_HERE'); if ($mysqli->connect_errno) { die("Connect failed: ($mysqli->connect_errno) $mysqli->connect_error"); } echo "Connected OK to MySQL and the database.";

Visit https://yourdomain.com/testdb.php.

  • If you see Connected OK, your credentials/host are correct.

  • If you see an error, fix the specific issue shown.
    Delete testdb.php immediately after testing.


7) Check disk usage & file count (inodes)

  1. cPanel → Disk Usage (and File Usage/Inodes if available).

  2. If near 100%, free space (delete old backups, cache, or logs).
    Low space can cause database operations to fail.


If it’s still not working

Try these quick isolations:

  • Temporarily disable all plugins by renaming the wp-content/plugins folder to plugins.off in File Manager (then rename back). This reduces load while you fix DB issues.

  • If your site was migrated recently, re-check that the DB name/user/password match the new server and that the DB user is assigned.


When to contact HostBible

If you’ve completed the steps and still see the error—especially if phpMyAdmin won’t load—reach out to HostBible Support. Include:

  • Your domain and a screenshot of the error.

  • The database name and database user you expect to use.

  • The time the issue started and any changes made just before it (updates, migrations, plugin installs).

  • Steps you already tried from this guide.


FAQ

What should DB_HOST be?
Usually localhost on cPanel hosting, unless you were explicitly given a different host by support.

I don’t know my DB password, can I retrieve it?
Passwords can’t be viewed, only reset in cPanel → MySQL® DatabasesCurrent UsersChange Password (then update wp-config.php).

Is repairing safe?
Yes - cPanel’s repair and WordPress’s repair are safe operations. Always keep backups.


Copy‑paste checklist

  • wp-config.php has the correct DB_NAME, DB_USER, DB_PASSWORD, DB_HOST.

  • DB user is assigned to the DB with ALL PRIVILEGES (cPanel → MySQL® Databases).

  • Database checked/repaired (cPanel checker or phpMyAdmin).

  • (Optional) WordPress repair run and then disabled.

  • Disk usage/inodes not full.

  • (Optional) Test script confirms successful connection.

  • Still stuck? Contact HostBible with details.

Did this answer your question?