Yes, this is the probably what we all done before, and tons of blog tips are cached by Google, but I want to have my own note for this).
Well find your MySQL configuration file that is named my.cnf. You may use locate index search in your Linux box if you previously installed it as follows
or use whereis command (Hey, I'm giving you 3 in 1 tip;):
open it with your favorite editor and and the following line to [mysqld] section:
Then restart mysql deamon with command like:
$sudo service mysql restart
$sudo /etc/init.d/mysql restart
or something specific for your distro. Now login to mysql with:
NB: just press enter when it asks you the password
and execute the following SQL command:
UPDATE mysql.user SET password = PASSWORD('newpassword') WHERE user = 'root' AND host = 'localhost';
if successful, go back to the shell (for ex. with Ctrl+C), remove recently added config entry and restart service again.
And that's it.
I used this russian article for reference: http://deathstar.name/vosstanovlenie-parolya-ot-root-v-mysql