In such cases when the password is lost, the user should start the DB with skip-grants-table and then change the password. Thereafter, with the new password, the user should restart the DB in normal mode.
Queries to be used:
a) To start DB with skip-grant-table: --skip-grant-tables
b) Connect to the MySQL server as the root user: mysql -u root
c) Use the following command to change the root password: UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
d) Flush the privileges: FLUSH PRIVILEGES;
e) Exit MySQL: Exit;
f) Restart MySQL in normal DB mode.