Fix WordPress Database Connection Error
WordPress says ‘Error establishing a database connection.’ Here’s how to find and fix the broken link.
“Error establishing a database connection” means WordPress can’t reach MySQL. The site is dead until this is fixed. The database itself is almost always fine. The problem is usually incorrect credentials in wp-config.php.
Step 1: Check wp-config.php Credentials
Open wp-config.php in your site root (via cPanel File Manager or SSH) and find these four lines:
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_user');
define('DB_PASSWORD', 'your_database_password');
define('DB_HOST', 'localhost');
Each value must match exactly what’s configured in cPanel. Check them:
Verify Database Name
- Go to cPanel > MySQL Databases
- Scroll to Current Databases
- Confirm the database name matches
DB_NAMEinwp-config.php
Note: cPanel prefixes database names with your username. If your cPanel username is gozen, your database is gozen_wordpress, not just wordpress.
Verify Database User
- Same page: MySQL Databases > Current Databases
- Check which user is assigned to the database
- Confirm it matches
DB_USERinwp-config.php
Same prefix rule applies: gozen_wpuser, not wpuser.
Verify Password
If you’re unsure of the password:
- Go to MySQL Databases
- Scroll to Current Users
- Click Change Password next to the database user
- Set a new password
- Update
wp-config.phpwith the new password
Verify DB_HOST
On GoZen Host shared and managed VPS plans, DB_HOST should be localhost. If you see an IP address or a remote hostname, change it to localhost (unless you’re running a remote database server).
Step 2: Check if MySQL is Running
Shared Hosting
You can’t restart MySQL on shared hosting. If the database server is down, it affects all accounts on the server. Contact support - we’ll see it on our monitoring and fix it.
VPS / Dedicated Server
sudo systemctl status mysql
# or
sudo systemctl status mariadb
If it’s not running:
sudo systemctl start mysql
If it won’t start, check the MySQL error log:
tail -50 /var/log/mysql/error.log
Common causes: disk full, corrupted InnoDB tablespace, or out of memory.
Step 3: Check Database Integrity
If credentials are correct and MySQL is running, the database might be corrupted.
Using wp-config.php
Add this line to wp-config.php (before the “stop editing” line):
define('WP_ALLOW_REPAIR', true);
Then visit: https://yourdomain.com/wp-admin/maint/repair.php
Click Repair Database (or Repair and Optimize for a more thorough fix).
Remove the WP_ALLOW_REPAIR line after you’re done. This page is accessible without login, so don’t leave it enabled.
Using phpMyAdmin
- Go to cPanel > phpMyAdmin
- Select your WordPress database
- Click Check All to select all tables
- From the dropdown at the bottom, select Repair table
Step 4: After a Migration
If this started happening after migrating to GoZen Host, the most common cause is the cPanel username prefix.
Your old host might have used database name wordpress with user wpuser. On GoZen, those become cpanelusername_wordpress and cpanelusername_wpuser.
Update all four values in wp-config.php to match the GoZen cPanel prefix.
What to Do Next
- Fix WordPress White Screen - if the site shows a blank page instead of the DB error
- Using Backuply - prevent this stress with proper backups
- How to Get Support - if MySQL is down, contact us and we’ll fix it
Last updated 07 Apr 2026, 00:00 +0200.