Here are the steps to reset the MySQL root password from the server command line:
Log in to the server via command line as 'root' user and run the following commands:
- Stop the currently running MySQL process:
#/etc/init.d/mysql stop
- Now start the MySQL process with the –skip-grant-tables option so that it will not prompt for the password:
#mysqld_safe --skip-grant-tables & - Once done, log in as root user without password using the following command:
#mysql -u root - Once logged in, set a new root password:
#mysql> use mysql;
#mysql> update user set password=PASSWORD("NEW PASSWORD") where User='root';
#flush privileges;
Need to replace "NEW PASSWORD" with the new password. - Exit from MySQL and then restart the service:
#service mysql stop
#service mysql start - Try to login using the new password:
#mysql -u root -p'NEW-PASSWORD'