How to reset the MySQL root password


If you have forgotten the mysql root passwod, you can set a new password if you have root access to the server.
1. Stop MySQL server.

# /etc/init.d/mysql stop

2. Start MySQL with –skip-grant-tables option.

# mysqld_safe –skip-grant-tables &

3. Connect to MySQL as root.

# mysql -u root

4. Set new mysql root password.

mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD(“NEW-PASSWORD”) WHERE user=’root’;
mysql> FLUSH PRIVILEGES;
mysql> quit

5. Stop and restart MySQL server.

# /etc/init.d/mysql stop
# /etc/init.d/mysql start