How to reset an unknown `root` password in MySQL 8?

Step 1

service mysql stop

Step 2

mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld

It fixes «Directory '/var/run/mysqld' for UNIX socket file don't exists».

Step 3

mysqld_safe --skip-grant-tables --skip-syslog --skip-networking

Step 4

Open a new terminal window.

Step 5

mysql -u root

Step 6

UPDATE mysql.user SET authentication_string=NULL WHERE user='root';

stackoverflow.com/a/63716361

Step 7

UPDATE mysql.user SET plugin='mysql_native_password' WHERE user='root';

It fixes «Plugin 'auth_socket' is not loaded».

Step 8

FLUSH PRIVILEGES;

Step 9

Stop mysqld_safe

Step 10

service mysql start

Step 11

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '<password>';
UPDATE mysql.user SET plugin='caching_sha2_password' WHERE user='root';