To change MySql database root password We have to restart MySql server with skip_grant_table option.
Edit my.cnf for linux file or my.ini file for windows and add following line in this file.
skip_grant_table=1 |
Then restart MySql Service. After restart you can log in MySql server without using password.
Change root password by running.
UPDATE mysql.user SET Password=PASSWORD('New_Password') WHERE User='root'; FLUSH PRIVILEGES; |
Remove skip_grant_table option and restart MySql. After that you can use your new password.