How to Restore a User's Database Access

Last modified: September 28, 2020


Overview

If a database user loses access to databases, you can restore the user’s grants to the database with the restoregrants utility.

The restoregrants script

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

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

The examples above use the following variables:

  • $cpuser — The cPanel username who lost access to their databases.
  • $dbuser — The database user whose privileges to restore.
    • If you use the --dbuser flag, $dbuser represents the database user.
    • If you use the --all flag, the script restores grants for all of the database users that belong to the cPanel account.
  • $type — The type of database:
    • mysql — MySQL®.
    • pg — PostgreSQL®.

Update password

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

If the script fails, either the cPanel user or the WHM user who owns the account (the reseller or system administrator) can reset the cPanel account’s password to restore grants.

The cPanel user can restore grants with the following steps:

  1. Navigate to cPanel’s Password and Security interface (cPanel » Home » Preferences » Password & Security).

  2. Select Allow MySQL password change.

  3. Enter the old password in the Old Password text box.

  4. Enter a new password in the New Password and New Password (again) text boxes.

  5. Click Change your password now.

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

  1. Navigate to WHM’s List Accounts interface (WHM » Home » Account Information » List Accounts).

  2. Click the + link next to the appropriate account.

  3. Select Sync MySQL password with account password.

  4. Enter a new password in the Change Password text box.

  5. Click Change.

Additional Documentation