After Searching a lot i got the solution of this error.
After Searching a lot i got the solution of this error.
This method works on mysql 5.7 and above version source stackoverflow.
The Steps are as follows:-
Step 1. Stop mysql-server:
systemctl stop mysqld
Step 2. Ater that set mysql-environment:
systemctl set-environment MYSQLD_OPTS=”–skip-grant-tables”
Step 3. Start the mysql-server using the following command:
systemctl start mysqld
Step 4. Login to mysql-server as root user:
mysql -u root
Step 5. Update the mysql-server root password using the command:
mysql> UPDATE mysql.user SET authentication_string = PASSWORD(‘YourPassword’) Where User =’root’ AND Host = ‘localhost’;
mysql> FLUSH PRIVILEGES;
mysql> quit
Step 6. Stop mysql -server
systemctl stop mysqld
Step 7. Unset the mySQL envitroment option so it starts normally next time systemctl unset-environment MYSQLD_OPTS
Step 8. Start mysql-server:
systemctl start mysqld
After that try to login using your new password
mysql -u root -p
Done Enojoy!!!