Commands
sudo /etc/init.d/mysql stop
Now start up MySQL in safe mode, so you'll skip the privileges table:
sudo mysqld_safe –skip-grant-tables &
Login with root:
mysql -uroot
And assign the DB that needs to be used:
use mysql;
Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:
update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';
flush privileges;
quit and restart MySQL:
quit
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
Now your root password should be working with the one you just set, check it with:
mysql -u root -p