If you’re managing your website on a cPanel hosting platform and suddenly your MySQL database becomes inaccessible for specific users, it’s likely due to incorrect privileges or broken database-user mappings. The need to restore database access is common—especially after migrations, backup restorations, or accidental deletions. Ensuring your database users have the correct permissions is critical for seamless website operation.

At HostraGo, we often get queries from users trying to fix broken database connections or facing MySQL errors such as “Access denied for user.” This guide will walk you through simple yet effective ways to restore database access manually using cPanel or WHM tools. If you’re a web developer, site owner, or hosting provider, this blog will help you regain control and resolve access issues swiftly.

Common Reasons Why Database Access is Lost

Before jumping into the solution, it’s important to understand why database access breaks. Common scenarios include:

  • restore database without associated database users
  • Changing hosting provider without importing user privileges
  • Deleting a user accidentally in cPanel
  • Permission misconfiguration
  • Incomplete database restoration process

Knowing the cause can help you avoid the same issue in the future.

How to use the restoregrants script?

Run one of the following commands from the command line to use the restoregrants script to restore the user’s database access:

/usr/local/cpanel/bin/restoregrants --cpuser=$cpuser --db=$type --dbuser=$dbuser
/usr/local/cpanel/bin/restoregrants --cpuser=$cpuser --db=$type  --all

Description of the variables used in the above example:

  • $cpuser — Refers to the cPanel username who lost their database access.
  • $dbuser — The database user who can restore the database.
    • If you use the --dbuser flag, $dbuser describe the database user.
    • If you use the --all flag, the script restores permissions for all database users associated with the cPanel account.
  • $type — Refers to the type of database:
    • mysql — MySQL®.
    • pg — PostgreSQL®.

How to Use the Update Password Method?

If you do not have SSH/root access, updating the MySQL user password from the cPanel interface is a simple workaround to re-sync user privileges.

Below are two scenarios depending on your level of access.

If You Are a cPanel User

Follow these steps to restore database access by updating the MySQL user password:

  1. Login to your cPanel account.
    URL: https://yourdomain.com:2083 or via your hosting provider (e.g., HostraGo Dashboard)
  2. Go to “MySQL Databases” under the Databases section.
  3. Scroll down to Current Users.
  4. Locate the MySQL user having issues and click Change Password next to it.
  5. Enter a new strong password and confirm.
  6. Click Change Password.
  7. Ensure the MySQL user is added to the correct database in the “Add User to Database” section.
  8. Click All Privileges > Make Changes.

This refreshes the user’s privileges and restores connectivity to the database.

If You Are a Server Administrator or a Reseller

You can follow these steps via WHM or manually through SSH/cPanel access for your client accounts:

  1. Login to WHM as root or reseller.
    URL: https://yourserverip:2087
  2. Navigate to List Accounts and choose the affected cPanel account.
  3. Click cPanel icon to log into the user’s control panel.
  4. Go to MySQL Databases > Locate the user under “Current Users”.
  5. Click Change Password, set a new one, and save.
  6. Reassign the user to the database if needed (via “Add User to Database”).
  7. Grant All Privileges to ensure full access.
  8. Confirm database connection by opening the website or testing via phpMyAdmin.

Why Is This Necessary?

  • During migrations or restorations, the MySQL user gets recreated, but privileges are not auto-restored unless included in the backup.
  • Changing the user password refreshes internal mapping in MySQL and cPanel, restoring access.

Final Thoughts

restore database access is a straightforward process once you understand the user-database relationship and privileges. With the right steps, tools, and guidance, you can regain access in minutes. If you’re managing multiple sites, automate backups and keep your credentials secure to avoid future issues.

Trust HostraGo for secure, fast, and reliable web hosting services with tools that make database management easier than ever!

Categorized in:

WHM,