停止MYSQL
systemctl stop mysqld
修改mysql的配置文件
vim /etc/my.cnf
在[mysqld]下增加
skip-grant-tables
启动MYSQL
systemctl start mysqld
登陆MYSQL
mysql -u root -p
更新ROOT密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '填写密码';
flush privileges;
最后
去掉再my.cnf文件下增加的skip-grant-tables,并重启mysql
其他
If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root. However, this is insecure. For instructions on assigning a password, see Section 2.10.4, “Securing the Initial MySQL Account”.
参考
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html