Fix: 'Error Establishing a Database Connection' on Your Website

Diagnose and resolve the 'Error establishing a database connection' message on your website, which may be caused by a temporary MySQL interruption, incorrect credentials, or a corrupted database.

Troubleshoot 5 min read Updated 2026-03-21 Beginner Cynet Support

Quick Answer

If all websites on your hosting suddenly show this error, it is most likely a temporary MySQL server interruption — wait 2–5 minutes and refresh the page. The database service auto-recovers. If the error persists on only your site, check your database credentials in wp-config.php (or your app's config file) and verify they match cPanel → MySQL Databases.

The "Error establishing a database connection" message appears when your website cannot connect to its MySQL database. This is one of the most common website errors and can be caused by several things — from a brief server hiccup to incorrect configuration.

Symptoms

  • Your website displays: "Error establishing a database connection"
  • The WordPress admin panel (/wp-admin) shows the same error or a "database repair" message
  • All pages on the site are affected, not just specific ones
  • The error may appear suddenly on a site that was previously working fine

Causes

Temporary MySQL Server Interruption (Most Common)

If the error appears suddenly across all websites on your hosting account, the MySQL server is likely experiencing a brief interruption. This can happen during:

  • Routine server maintenance
  • High load on the database server
  • Automatic MySQL service restarts
This resolves itself automatically within 2–5 minutes. Simply wait and refresh the page.

Incorrect Database Credentials

Your website's configuration file contains the wrong database name, username, password, or host. This often happens after:

  • Changing the database user's password in cPanel without updating the config file
  • Migrating the site from another server
  • Restoring a backup from a different hosting account

Database User Not Assigned

The database user exists but is not assigned to the database (or privileges were removed).

Database Deleted or Renamed

The database referenced in the config file no longer exists in cPanel.

Disk Quota Exceeded

If your hosting disk space is full, MySQL cannot write temporary files and may refuse connections. See Fix: Disk Quota Exceeded.

Corrupted Database Tables

Database tables may become corrupted due to an interrupted write operation, server crash, or disk error.

Solution

Step 1: Wait and Refresh

If the error just appeared out of nowhere:

  1. Wait 2–5 minutes
  2. Refresh the page
  3. If the site loads, it was a temporary MySQL interruption — no further action needed
Tip: Check if other websites on your hosting account are also affected. If all sites show the error simultaneously, it's almost certainly a temporary server-side interruption.

Step 2: Verify Database Credentials

If the error persists, check that your configuration file has the correct database details.

For WordPress

  1. Log in to cPanel → File Manager → navigate to /publichtml/
  2. Open wp-config.php (right-click → Edit)
  3. Find these four lines:
define('DBNAME', 'cpaneluserdbname');
define('DBUSER', 'cpaneluserdbuser');
define('DBPASSWORD', 'yourpassword');
define('DBHOST', 'localhost');
  1. Verify each value against cPanel:
- DBNAME: Go to cPanel → MySQL Databases → check under "Current Databases" - DBUSER: Same page → check under "Current Users" and confirm the user is assigned to the database - DBPASSWORD: If unsure, reset the password in cPanel → MySQL Databases → Change Password for the user - DBHOST: Should be localhost on Cynet hosting
  1. If you changed the password, update wp-config.php with the new password and save

For Other Applications (Laravel, Joomla, Custom PHP)

Check the database connection settings in your application's config file:

  • Laravel: .env file (DBDATABASE, DBUSERNAME, DBPASSWORD, DBHOST)
  • Joomla: configuration.php ($db, $user, $password, $host)
  • Custom PHP: Wherever your database connection is defined

Step 3: Check Database User Privileges

  1. Go to cPanel → MySQL Databases
  2. Scroll to Current Databases
  3. Confirm your database user is listed under Privileged Users for that database
  4. If not, scroll to Add User To Database → select the user and database → click Add → check All Privileges → click Make Changes

Step 4: Repair the Database

If credentials are correct but the error persists, the database may be corrupted.

WordPress Database Repair

  1. Add this line to wp-config.php (before "That's all, stop editing!"):
define('WPALLOWREPAIR', true);
  1. Visit https://yourdomain.com/wp-admin/maint/repair.php
  2. Click Repair Database or Repair and Optimize Database
  3. Once complete, remove the line from wp-config.php (leaving it is a security risk)

phpMyAdmin Repair

  1. Go to cPanel → phpMyAdmin
  2. Select your database from the left sidebar
  3. Click Check All to select all tables
  4. From the dropdown at the bottom, select Repair table
  5. Click Go

Step 5: Check Disk Space

  1. Go to cPanel → Disk Usage
  2. If usage is at or near 100%, you need to free up space
  3. See Fix: Disk Quota Exceeded for detailed instructions

Step 6: Contact Support

If none of the above steps resolve the issue:

  • The MySQL server may require a restart on the server side
  • There may be a broader server issue
Submit a support ticket to Cynet at manage.cynet.com.my with:
  • Your domain name
  • When the error started
  • Whether all sites or just one site is affected
  • Steps you've already tried

Prevention

  • Don't edit database credentials unless necessary — if you change a database password in cPanel, immediately update your config file
  • Keep regular backups — Use Softaculous, WP Toolkit, or cPanel Backup to maintain recent backups
  • Monitor disk space — Keep usage below 90% to avoid write failures
  • Use a caching plugin — Reduces database load and makes your site more resilient to brief MySQL interruptions
  • Optimise your database — Periodically clean up post revisions, spam comments, and transient data using a plugin like WP-Optimize
database MySQL error WordPress hosting connection troubleshoot

Need our team to handle this?

Running into a hosting issue you can't resolve? Submit a request and our engineers will help.

Was this article helpful?

Not sure which hosting plan is right for you?

Get a personalized recommendation in under 60 seconds.

Find the Right Plan