一、编辑mysql配置文件 etc/my.conf 执行如下命令
#默认目录
vim etc/my.cnf
#如果是docker启动,在挂载目录下
vim //devtools/mysqldata/conf/my.conf
二、在文件配置内容的 [mysqld] 节点下加入 skip-grant-tables 如下:
三、连接 mysql 服务,可以跳过密码登录
mysql -uroot -p
系统提示输入密码,可以直接回车登入
四、重新设置 root 密码即可
# 第一步
use mysql
# 第二步,设置校验密码策略为LOW或0,只验证长度。设置密码长度为6位
set global validate_password.policy=LOW;
set global validate_password.length=6;
# 第三步,刷新特权
flush privileges;
# 第四步,授权所有库和表,给所有IP访问的root用户权限
grant all privileges on *.* to 'root'@'%' with grant option;
# 第五步,重置密码为root123456
alter user root@'%' identified with mysql_native_password by 'root123456';
五、去掉 etc/my.conf 配置内容中的 skip-grant-tables 参数,重启服务,再次登录即可