When you forgot the mysql root password and can not log in to change the password.
Use sudo or root
systemctl stop mysqld.service # systemd
rc-service mysql stop # openrc
While running, DO NOT press control- {c, d, z}
mysqld_safe --skip-grant-tables
mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
After giving Ctrl + Z on the previous tab and kill the process, or simple exit and close the corresponding terminal or tab.
systemctl start mysqld.service # systemd
rc-update start mysqld.service # openrc
# Now login, normal user or root user
mysql -u root -p