How to reset root password

MySQL 5.7.6 and later

Modify /etc/my.cnf, append skip-grant-tables.

sed -i '/[mysqld]/a skip-grant-tables' /etc/my.cnf

Restart mysql server, update root password.

select user,host,authentication_string from mysql.user;
update mysql.user set authentication_string=password('Jove!123') where user='root';
flush privileges;

MySQL 5.7.5 and earlier

Modify /etc/my.cnf, append skip-grant-tables.

sed -i '/[mysqld]/a skip-grant-tables' /etc/my.cnf

Restart mysql server, update root password.

select user,host,password from mysql.user;
update mysql.user set password=password('Jove!123') where user='root' and host='localhost';
flush privileges;