This article walks you through manually resetting the MySQL root password if the password in the
/root/.my.cnf becomes desynced. When possible, we recommend using the WHM interface to make these changes:
Please note the steps below should only be used if the WHM interface can not be used to reset the password. This is best performed by a qualified system administrator, and cPanel support staff are not able to perform these steps for you.
- Log in to WHM, select Service Manager under the 'Service Configuration' section, and disable monitoring for the MySQL service.
- Connect to the server via SSH as the root user.
- Stop the MySQL service:
- Create a text file in
- Open the file in a text editor and add the following text to the file, where MyNewPass represents the password you would like to use:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
- Update the password in
/root/.my.cnfto the password used in this statement:
[root@server]# grep -i pass /root/.my.cnf password="MyNewPass"
- Change the ownership of the file to ensure there are no issues reading the file:
chown -v mysql. /var/lib/mysql/mysql-init
- Start MySQL manually using this command:
mysqld -u mysql --init-file=/var/lib/mysql/mysql-init &
- Now that the password has been updated shut down MySQL safely using this command:
mysqladmin -u root shutdown
- Remove the init file:
/bin/rm -vi /var/lib/mysql/mysql-init
- Restart MySQL normally:
- In the WHM interface, re-enable MySQL service monitoring in Service Manager >> Service Configuration.
When using MySQL 5.7:
It may be necessary to use the following statement in place of the ALTER statement shown above:
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
More information on these steps can be found in the official MySQL documentation here:
The following article can show you how to edit text files using command line tools: