步骤:
1.先停掉mysqld服务
systemctl stop mysqld
2.可选:
进入/etc/my.cnf配置文件把 validate_password=off参数注释掉。(如果有的话)
3.执行:
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
或者
mysqld_safe --skip-grant-tables &
4.开启mysql服务
systemctl start mysqld
5.直接登陆mysql -uroot
6.修改密码
mysql> alter user 'root'@'localhost' identified by '1234567';
mysql> flush tables;
7.退出后就可以再次用密码进入了。
网友评论