First stop the mysql service
service mysqld stop
or
systemctl mysqld stopStart mysql with safe mode
sudo mysqld_safe --skip-grant-tablesLog into MySQL as root:
mysql -u rootChange to the mysql database, which handles the settings for MySQL itself:
use mysql;Update the password for the root user:
update user set password=PASSWORD("newpassword") where User='root';Refresh the MySQL user privileges:
flush privileges;Exit MySQL:
exitRestart mysql back and retry to login with new password
mysql -u root -p