MySQL Database Not Connecting in cPanel

Estimated reading: 4 minutes

A MySQL database connection error can cause your website or application to stop working entirely. Whether you’re running WordPress, Joomla, Laravel, or another PHP application, a failed database connection usually means your website cannot retrieve the data it needs.

The good news is that most MySQL connection issues can be resolved with a few troubleshooting steps in cPanel.

This guide covers the most common causes and how to fix them.

What Causes MySQL Database Connection Errors?

A MySQL connection can fail for several reasons, including:

  • Incorrect database username or password
  • Wrong database hostname
  • Corrupted database tables
  • Database user not assigned
  • MySQL server temporarily unavailable
  • Exceeded database limits
  • Incorrect configuration file
  • Database import problems

Common Error Messages

You may encounter messages such as:

  • Error Establishing a Database Connection
  • Access denied for user
  • Can’t connect to MySQL server
  • MySQL server has gone away
  • Database connection failed
  • SQLSTATE[HY000]

Solution 1: Verify Database Credentials

Incorrect login credentials are the most common cause.

Open your application’s configuration file.

For WordPress:

wp-config.php

Check these values carefully:

DB_NAME
DB_USER
DB_PASSWORD
DB_HOST

Make sure they exactly match the database information in cPanel.

Even an extra space or incorrect capitalization can prevent the connection.

Solution 2: Verify the Database Exists

In cPanel:

  1. Open MySQL Databases.
  2. Confirm your database exists.
  3. Verify the database name matches your application’s configuration.

Remember that cPanel automatically adds your account username as a prefix.

Example:

username_website

instead of simply:

website

Solution 3: Make Sure the Database User Exists

Inside MySQL Databases, check that your database user still exists.

If it was accidentally deleted:

  1. Create a new database user.
  2. Assign a secure password.
  3. Update your application configuration if necessary.

Solution 4: Assign the User to the Database

Even if both the database and user exist, they must be linked together.

In cPanel:

  1. Open MySQL Databases.
  2. Scroll to Add User to Database.
  3. Select the correct user.
  4. Select the correct database.
  5. Click Add.
  6. Grant All Privileges.

Without proper privileges, MySQL will deny access.

Solution 5: Repair Corrupted Database Tables

Corrupted tables can prevent successful connections.

For WordPress:

Add the following line to your wp-config.php file:

define('WP_ALLOW_REPAIR', true);

Then visit:

yourdomain.com/wp-admin/maint/repair.php

Run the repair process.

After completing the repair, remove the line from wp-config.php.

Solution 6: Check the Database Host

Most cPanel hosting accounts use:

localhost

However, some VPS or cloud hosting providers use a different hostname.

If you’re unsure, verify the correct MySQL hostname with your hosting provider.

Solution 7: Restore a Recent Backup

If the problem started after a migration, plugin installation, or accidental deletion, restoring a recent backup may resolve the issue.

You can restore:

  • Database only
  • Full website backup
  • Full cPanel account backup

Always create a backup before making major changes.

Solution 8: Check Database Size Limits

Large databases can sometimes exceed hosting limits or encounter timeout issues during imports.

If your database has grown significantly:

  • Remove unnecessary logs
  • Delete unused tables
  • Optimize tables
  • Consider upgrading your hosting plan if needed

Solution 9: Optimize Database Tables

Over time, database tables become fragmented.

Inside phpMyAdmin:

  1. Select your database.
  2. Select all tables.
  3. Choose Optimize Table.

This improves performance and can resolve minor issues.

Solution 10: Check phpMyAdmin Access

Open phpMyAdmin in cPanel.

If phpMyAdmin cannot access the database either, the issue is likely server-side rather than with your website configuration.

This can indicate:

  • Corrupted database
  • MySQL service problems
  • Account permission issues

Solution 11: Check Recent Website Changes

Think about what changed before the issue appeared.

Common causes include:

  • Installing a new plugin
  • Updating WordPress
  • Website migration
  • Changing database credentials
  • Restoring an old backup
  • Editing wp-config.php

Undoing the recent change may immediately resolve the issue.

Solution 12: Contact Your Hosting Provider

If none of the above solutions work, your hosting provider can check:

  • MySQL server status
  • Error logs
  • User permissions
  • Resource usage
  • Database corruption
  • Server connectivity

Server logs often reveal the exact cause of the problem.

Frequently Asked Questions

Why does WordPress say “Error Establishing a Database Connection”?

This usually means WordPress cannot connect to the MySQL database because of incorrect credentials, a corrupted database, or a MySQL server issue.

Does changing my cPanel password affect MySQL?

No. Your cPanel login password is separate from your MySQL database user’s password unless you manually change both.

Can deleting a database user break my website?

Yes. If your application relies on that user for database access, deleting it will immediately cause connection failures.

Can a full disk cause database issues?

Yes. If your hosting account reaches its storage limit, MySQL may fail to write data correctly, leading to errors or reduced performance.

Launchpad