BuycPanel Blog

BuycPanel Blog

Latest news and updates

How to Restore a User’s Database Access

Posted by Allura on 30 07 2018.


In case a user of a database cannot access the databases, you can then restore their access privileges using the restoregrants utility.

Running the restore grants script

You can use one of the following commands to re-establish database for a user access through the restoregrants script:

  1. /usr/local/cpanel/bin/restoregrants –cpuser=$cpuser –db=$type –dbuser=$dbuser
  2. /usr/local/cpanel/bin/restoregrants –cpuser=$cpuser –db=$type  –all


In the table given below you will find variables that are used by the example above:


$cpuserThe stands for the username of the cPanel user who cannot gain access to their databases.username
$typeThe database category:

●        mysql for MySQL

●        pg for PostgreSQL®

$dbuserThis includes the user of your database whose access privileges you want to restore.

●        While using the –dbuser flag, $dbuser stands for the database user.

●        While using the –all flag, the script re-establishes grants for all of the database users belonging to the cPanel account.


Updating Password of cPanel User

It might not always be possible to restore database access for the user using the restoregrants script. In case the script fails, there are still ways in which the access can be restored. The owner of the account, who may either be a WHM user or a cPanel user, can restore the account password to grant access to the user. The reseller or server administrator can also re-establish grants for the user who wants to access the database.

A cPanel user can use the following steps to re-establish access to database:

  1. Go to the Password and Security interface on cPanel. Find the option at cPanel > Home > Preferences > Password & Security.
  2. Choose the option Allow MySQL password change.
  3. Enter your previous password in the Old Password text box.
  4. Your new password goes in the New Password text box. You have to enter it twice.
  5. Confirm by clicking Change your password now.

The reseller or server administrator can restore grants with the steps mentioned below:

  1. Go to the List Accounts interface on WHM. It is located at WHM >> Home >> Account Information >> List Accounts.
  2. Find the particular account and click on the + link next to it.
  3. Click on Sync MySQL password with account password.
  4. Set a new password in the Change Passwordtext box.
  5. Click on Change to confirm.


There are workarounds available in case a user is unable to access the files in a database. Follow the steps outlined in this article to restore grants to the user.