How to reset root password in mariadb or mysql server v5.6+?

/etc/init.d/mysql stop

mysqld_safe --skip-grant-tables &

mysql -u root

 

use mysql;

update user set authentication_string=PASSWORD("mynewpassword") where User='root';

flush privileges;

quit

 

/etc/init.d/mysql stop

/etc/init.d/mysql start

 

mysql -u root -p