1#First Login with administrative account (Even root itself)
2
3mysql> use mysql;
4mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("NewPassword");
5mysql> flush privileges;
6
7#Now quit and login
8mysql> quit
9
10mysql -u root -p
11#Click enter and It will prompt you to enter password
12#Just to be safe you should also still try to log in without entering a password
1use mysql;
2
3update user set authentication_string=PASSWORD("mynewpassword") where User='root';
4
5flush privileges;
6
7quit
8
11. If you in skip-grant-tables mode in mysqld_safe:
2
3mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';
4mysql> FLUSH PRIVILEGES;
5mysql> exit;
6
7and then, in terminal:
8
9$ mysql -u root
10
11in mysql:
12mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
13
14
152. Not in skip-grant-tables mode just in mysql:
16mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';