How to reset default mysql 8.0 root password on CentOs

The initial root password on install can be found by running

grep 'temporary password' /var/log/mysqld.log

stop mysql service

systemctl stop mysqld

Change mysql environment option

systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

Start mysql with above option enabled

systemctl start mysqld

Login as root

mysql -u root

Update the root user password with these mysql commands

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpasswd';

Stop mysql

systemctl stop mysqld

Unset the mySQL envitroment options

systemctl unset-environment MYSQLD_OPTS

Start mysql normally

systemctl start mysqld

Login using your new password

mysql -u root -p

Extra tips

Allow remote access

You can find more information on mysql developer documents

Let me know if you have more addition for this flow. Thanks.