Tag Archives: Database Grants

Restoring Database Grants On WHM Server & cPanel

When a database user loses his access to configured databases, you may need to restore that user’s grants to the database using the restoregrants utility on WHM.

The first step you need to make is to access your command line and then use restore grants to restore the user’s database access:

/usr/local/cpanel/bin/restoregrants –cpuser=$cpuser –db={mysql, pg} –dbuser=$dbuser

/usr/local/cpanel/bin/restoregrants –cpuser=$cpuser –db={mysql, pg} –all

Where:

  • $cpuser – is the cPanel username that has lost access to databases.
  • {mysql, pg} –  is the type of database: mysql for MySQL or pg for PostgreSQL.
  • $dbuser – is a database user whose privileges you wish to restore. If you use –dbuser, the $dbuser variable will consist of the database user’s name. If you use –all, the script will restore grants for all of the database users that belong to the cPanel account.

How to update the user’s password to restore database access on cPanel?

In certain circumstances, the restoregrants script may fail to restore access to the database.

In such a case, either the cPanel or the WHM  account owner can reset the cPanel account’s password in order to restore grants by following the given steps.

For restoring grants from cPanel:

  1. Navigate to cPanel > Change Password.
  2. Select Allow MySQL password change.
  3. Change the password and click Change your password now.

Steps for server administrator i.e. the owner of the WHM account:

  1. Navigate to WHM > List Accounts.
  2. Click + next to the appropriate account.
  3. Select Sync MySQL password with the account password.
  4. Enter a new password into the Change Password box and click Change.