Reset MySQL 5.7 root password on Ubuntu 16.04

First stop MySQL with command

Now run

On Ubuntu 16.04 server with MySQL 5.7, when i run, i get following error.

To fix, this error, create a the folder and change ownership to user mysql

Now start a new terminal, login to MySQL with command

You can press enter for password, you will be logged in with no password.

To reset MySQL root password, run

Now kill the MySQL process with command

Start MySQL normally with