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