Knowledge Base

How Can We Help?

How to Reset MySQL Root Password and Restore Database Grants in cPanel Server?

You are here:

Resetting MySQL root Password

To reset the root password for MySQL, we will use the command line in a Linux server. This method can also be used in a cPanel server, but there might be a drawback. WHM will not recognize the new root MySQL password and database functions will fail with access denied from MySQL. Therefore, in a cPanel server, it is recommended to reset the MySQL root password through WHM.

Please visit the following link to learn how to reset the MySQL root password in a Linux server via the command line.

In this tutorial, we will guide you on how to reset the MySQL root password through WHM.

1) Log in to WHM as the root user.

2) From there, select “SQL Services”.

Reset Mysql Password

3) Click on the “MySQL Root Password” button.

Reset Mysql Password

4) Now, enter the new password and click on the “Change Password” button.

Reset Mysql Password

Restoring Database Grants.

cPanel provides the “restoregrants” utility to restore the user’s database access.

1) Log in to the server as the root user via SSH.

2) Run either of the following commands from the command line.

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

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

$cpuser is the cPanel username that has lost access to databases.

mysql, pg is the database type: mysql for MySQL or pg for PostgreSQL

$dbuser >> The database user whose privileges you need to restore. If you use the –dbuser flag, the $dbuser variable will contain the database user’s name. If you use the –all flag, the script will restore grants for all the database users that the cPanel account owns.

If you need any further assistance, please reach out to our support department.

Leave a Comment