Here is an interesting thing I have found out that is if you have server access of database you want to login to Mysql server even you do not have root password of database.
I’m going to login database server with any password obviously it will not allow me so here is the solution.
See I got the message access denied Error 1045
Run this command to get temporary password to login on database server
Grep ‘temporary password’ /var/log/mysqld.log
It will provide you to the temporary password to login Mysql server. So you can login with that password then update root password.
If you face any issue in running above command then try to stop mysqld service