run the below command
[root ~]#service mysqld stop
[root ~]#mysqld_safe --skip-grant-tables
open the server in a new session and open the mysql without the password
[root ~]# mysql
mysql>use mysql;
For MySQL < 5.5
mysql>update user set Password=PASSWORD('new-password') where user='root';
mysql>flush privileges;
mysql>exit;
For MySQL 5.7
mysql>update user set authentication_string=PASSWORD('new-password') where user='root';
mysql>flush privileges;
mysql>exit;