Stop your databases
service mysqld stop
Modify /etc/my.cnf file add skip-grant-tables
sudo nano /etc/my.cnf
Add skip-grant-tables
in [mysqld] section
[mysqld]
skip-grant-tables
Start MySQL
service mysqld start
Select MySQL default database
mysql -u root
mysql> use mysql;
# Set a new password
mysql> update user set authentication_string=PASSWORD("yourpassword") where User='root';
Restart MySQL database
service mysqld restart
mysql -u root -p