Fixing Error Establishing Database Connection
The "Error Establishing a Database Connection" message is one of the most common issues for websites that rely on MySQL databases. This error means your website cannot communicate with its database. Here is how to diagnose and fix it.
Common Causes
- Incorrect database credentials – The username, password, or database name in your configuration file is wrong.
- Database server is down – The MySQL service may be temporarily unavailable.
- Corrupt database – One or more database tables may be corrupted.
- Exceeded resource limits – Your hosting account may have hit its connection or storage limits.
Step 1: Verify Database Credentials
Check your website's configuration file to ensure the database details are correct:
- WordPress – Check
wp-config.phpin your site root forDB_NAME,DB_USER,DB_PASSWORD, andDB_HOST. - Joomla – Check
configuration.phpfor the$db,$user,$password, and$hostvariables. - Custom PHP – Check your database connection file for the correct credentials.
Compare these values with the database and user listed in cPanel > MySQL Databases. Ensure the user is assigned to the database.
Step 2: Check If MySQL Is Running
Try accessing phpMyAdmin from cPanel. If phpMyAdmin loads and you can see your databases, the MySQL server is running. If phpMyAdmin also fails, the MySQL service may be down. Contact SillyHost support immediately.
Step 3: Repair the Database
If credentials are correct but the error persists, try repairing the database:
- Open phpMyAdmin and select your database.
- Select all tables using Check All.
- From the dropdown, choose Repair table.
For WordPress, you can also add define('WP_ALLOW_REPAIR', true); to wp-config.php and visit yourdomain.com/wp-admin/maint/repair.php. Remove this line after the repair is complete.
Step 4: Check Disk Space
If your hosting account has run out of disk space, MySQL cannot write data. Check your disk usage in cPanel and free up space by deleting unnecessary files, cleaning your database, or upgrading your plan.
Prevention
Keep regular backups, monitor your disk usage, and avoid making manual changes to database credentials without testing the connection first.