If you forget the MySQL root password on MySQL 8.0 server, you can follow the instruction here to reset the root user password.
First, stop the MySQL server if it is already running
systemctl stop mysql
Create folder
mkdir /var/run/mysqld/ chown mysql:mysql /var/run/mysqld/
Now start MySQL with –skip-grant-tables option
mysqld --skip-grant-tables --user=mysql
Take a new terminal, connect to MySQL
mysql -u root -p
When it asks for the root password, just press enter. No need to enter any password. To reset MySQL root password, run
FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'MySQL_NEW_ROOT_PW_HERE';
After running the above 2 SQL commands, exit MySQL command prompt with command exit or press CTRL+D.
Now you need to find the process ID of MySQL
ps aux | grep mysql
Kill the process with
kill -9 PROCESS_ID_OF_MYSQLD
Now start MySQL normally with
systemctl start mysql
Now you will be able to login to the MySQL server using the new PASSWORD
mysql -u root -p
See MySQL root password, MySQL Could not create unix socket lock file