If you forget the root password, you can reset it by two methods, explained as follows.
Resetting the root password
How to do it...
Let's get into the details.
Using init-file
On Unix-like systems, you stop the server and start it by specifying init-file. You can save the ALTER USER 'root'@'localhost' IDENTIFIED BY 'New$trongPass1'  SQL code in that file. MySQL executes the contents of the file at startup, changing the password of the root user:
- Stop the server:
shell> sudo systemctl stop mysqld
shell> pgrep mysqld...