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
- Open Services, choose your hosting and press Login to cPanel.
- Open Files › File Manager and go into public_html (or the folder of that site).
- Right-click
wp-config.phpand choose Edit. - 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
- Go back to cPanel and open Databases › MySQL Databases.
- Under Current Databases, check that a database with exactly the
DB_NAMEvalue exists. Remember that cPanel puts your cPanel username and an underscore in front. - In the same row, the Privileged Users column must show the
DB_USERvalue. 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. - 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.
- In MySQL Databases, under Current Users, press Change Password next to the user.
- Press Password Generator, copy the new password and press Change Password.
- Back in
wp-config.php, replace the oldDB_PASSWORDvalue with the new one. Keep the quote marks. - 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:
- In cPanel, open phpMyAdmin and click your database on the left.
- You should see tables like
wp_optionsandwp_posts. The first part (wp_) must match the$table_prefixline inwp-config.php. - If the database is empty, the import didn't finish. Import your
.sqlfile 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.