NetPoa

Fix "Error establishing a database connection" in WordPress

Updated 27 Nov 2026

Your website shows a white page with just Error establishing a database connection. WordPress can't reach its database, so it can't show any content. Your posts and pages are almost always still safe. Usually one setting is wrong.

This often happens right after moving a site, restoring a backup or changing a database password.

Step 1: Look at the settings in wp-config.php

  1. Open Services, choose your hosting and press Login to cPanel.
  2. Open Files › File Manager and go into public_html (or the folder of that site).
  3. Right-click wp-config.php and choose Edit.
  4. Find these four lines and write down the values:
define( 'DB_NAME', 'cpuser_duka' );
define( 'DB_USER', 'cpuser_dukauser' );
define( 'DB_PASSWORD', 'the-password' );
define( 'DB_HOST', 'localhost' );

Step 2: Compare them with cPanel

  1. Go back to cPanel and open Databases › MySQL Databases.
  2. Under Current Databases, check that a database with exactly the DB_NAME value exists. Remember that cPanel puts your cPanel username and an underscore in front.
  3. In the same row, the Privileged Users column must show the DB_USER value. If it doesn't, scroll down to Add User To Database, choose that user and database, press Add, tick ALL PRIVILEGES and press Make Changes.
  4. Under Current Users, check that the user exists.

DB_HOST should be localhost on our hosting. If it says anything else, for example the name of your old host's server, change it to localhost.

Step 3: Reset the database password

If the names are right, the password is the most likely problem. Set a new one and put the same one in WordPress.

  1. In MySQL Databases, under Current Users, press Change Password next to the user.
  2. Press Password Generator, copy the new password and press Change Password.
  3. Back in wp-config.php, replace the old DB_PASSWORD value with the new one. Keep the quote marks.
  4. Press Save Changes and reload your website.

Step 4: Check that the tables are there

If the error has changed to "One or more database tables are unavailable", or the site still won't load:

  1. In cPanel, open phpMyAdmin and click your database on the left.
  2. You should see tables like wp_options and wp_posts. The first part (wp_) must match the $table_prefix line in wp-config.php.
  3. If the database is empty, the import didn't finish. Import your .sql file again, or restore from a backup.

To repair damaged tables, add this line to wp-config.php just above "That's all, stop editing!":

define( 'WP_ALLOW_REPAIR', true );

Then open https://yourdomain.co.tz/wp-admin/maint/repair.php and press Repair Database. Remove the line again when you are done, because anyone can open that page while it is there.

Other causes

  • Your hosting is out of disk space. The database can't write, so it stops. In cPanel, check Disk Usage in the right-hand panel. See See what is using your disk space.
  • It came back by itself after a few minutes. A busy plugin or a traffic spike may have used all connections. If it keeps happening, open a ticket and tell us the times.

Stuck? Open a ticket and choose Technical. Our team can do it for you. Not hosting with us yet? See our cPanel hosting plans.

Was this helpful?