First stop the mysql service

service mysqld stop
or 
systemctl mysqld stop

Start mysql with safe mode

sudo mysqld_safe --skip-grant-tables

Log into MySQL as root:

mysql -u root

Change 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:

exit

Restart mysql back and retry to login with new password

mysql -u root -p