First, you need to stop the MySQL service. Follow this command to stop the MySQL Service.
sudo service mysql stopNext step is, you must start MySQL service again but with --skip-grant-tables option.
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
Because you are not checking the privileges when start the MySQL Service. It is better for you to stop the Networking to prevent the security less action.
The next, login to the MySQL server using root account.
mysql -u rootAfter login with root account without password, please flush the privileges using this command
FLUSH PRIVILEGES;Then, update your password
SET PASSWORD FOR root@'localhost' = PASSWORD('your password');Then FLUSH PRIVILEGES again. Now, your password has been changed. Do not forget to restart your MySQL Service, with this command:
sudo service mysql restart