If a database user loses access to databases, you can restore their grants using the restoregrants utility. This guide covers two methods: using the command-line script or resetting the account password to trigger automatic grant restoration.

How to Restore Database Access

  1. Step 1: Run the restoregrants script

    Execute one of the following commands from the command line, depending on whether you want to restore a specific database user or all users:

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

    The variables are:

    • $cpuser: The cPanel username experiencing a loss of access to their databases.
    • $dbuser: The database user for whom privileges need restoration (when using --dbuser flag). If using --all flag, the script restores grants for all database users associated with the cPanel account.
    • $type: The database type — mysql for MySQL® or pg for PostgreSQL®.

Alternative Method: Password Update

If the restoregrants script fails to restore database access, either the cPanel user or the WHM user overseeing the account (reseller or system administrator) can reset the cPanel account's password to restore grants.

For cPanel Users

  1. Step 1: Navigate to Password and Security

    Go to cPanel's Password and Security interface (cPanel » Home » Preferences » Password & Security).

  2. Step 2: Enable MySQL password change

    Enable "Allow MySQL password change."

  3. Step 3: Enter old password

    Input the old password in the Old Password text box.

  4. Step 4: Enter new password

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

  5. Step 5: Change password

    Click "Change your password now."

For Server Administrators or Resellers

  1. Step 1: Access List Accounts

    Go to WHM's List Accounts interface (WHM » Home » Account Information » List Accounts).

  2. Step 2: Select the account

    Click the + link next to the relevant account.

  3. Step 3: Sync MySQL password

    Choose "Sync MySQL password with account password."

  4. Step 4: Enter new password

    Input a new password in the Change Password text box.

  5. Step 5: Apply changes

    Click "Change."