Pratical and best guide that i have tried from many others that founded on web about how to reset mysql root password on linux server.
When you have this error, on you Ubuntu or Centos server (I have tried on Centos, and the user in the original post tried on Ubuntu):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
This is the guide to reset your mysql password:
$ sudo -s
# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
After logged as user root, reset the password:
mysql> use mysql;
mysql> update user set password=PASSWORD(’__NEW__PASSWORD__’) where User=’root’;
mysql> flush privileges;
# /etc/init.d/mysql start
And then, remember take a backup of your file!!
mysqldump -u root -p --all-databases > alldb.sql
Thank you to http://forum.ubuntu-it.org/viewtopic.php?t=293129