This is a quicker, less intrusive method with less downtime to reset mysql root password:
Create the following file and then enter the command that follows
vim /var/lib/mysql/mysql.init
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('mynewpassword');
Now edit: /etc/my.cnf and enter the following under the [mysqld] block
init_file=/var/lib/mysql/mysql.init
service mysqld restart
mysql -u root -p
Now delete the /var/lib/mysql/mysql.init and init_file=/var/lib/mysql/mysql.init line entered in /etc/my.cnf file
DONE
Changing mysql root password when you have lost the original password.
sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &
Now type the following command, you should not be prompted for a password when you enter this command
mysql -u root
Now select the database we are going to use with:
use mysql;
Change the password for root user with:
update user set password=PASSWORD("mynewpassword") where User='root';
The flush privileges;
flush privileges;
Now exit out of mysql.
You will now need to stop mysql and then start it again. The commands will vary slightly depending on if you are using CentOS or Ubunut/Debian.
You should see something similar to the following once you have stopped mysql:
root@linux ~]# service mysqld stop
150404 20:55:28 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld: [ OK ]
[1]+ Done sudo mysqld_safe --skip-grant-tables