mysql 8.0 版本以上的忘记密码怎么办
-
停止mysql服务
[root@sr2 ~]# systemctl stop mysqld -
修改配置文件
[root@sr2 ~]# vim /etc/my.cnf
放开这个(如果是自己配置的文件,加上这句即可) -
重启服务
[root@sr2 ~]# systemctl start mysqld -
登入
[root@sr2 ~]# mysql -uroot
这里它是免密登陆的
mysql> use mysql; -
修改密码
mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)mysql> alter user ‘root’@'localhost’IDENTIFIED BY ‘你的密码’;
Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) -
退出并停止服务
[root@sr2 ~]# systemctl stop mysqld -
修改配置文件
(务必将它注释掉,否则重新启动依然不需要密码) -
重启服务登录就好了