First please ensure that you really forgot the root password.

mysql -u root -p

If you really forgot the password then resetting the password is needed. Use dpkg-reconfigure to reconfigure the root user.

####Check the MySQL version First of all check the MySQL server version like this:

apt-cache policy mysql-server

the above command gave me output like:

Installed: 5.5.37-0ubuntu0.12.04.1

####Start reconfiguring the MySQL Start using the following shell command:

sudo dpkg-reconfigure mysql-server-*.*

Please, put your MySQL version name instead of mysql-server-. . For me I have used mysql-server-5.5 . It will stop the database and promt for reconfiguration.

dpkg-reconfigure

You can now enter your new password for the root user and so on. After the reconfiguration is completed the MySQL server will be automatically started.

Now you can login using your new password like this:

mysql -u root -p

That’s all for now. Thank you.