mysql 8.0.20 忘记密码,修改密码

由于mysql更新较快,8.0对比5.7很多操作有了变化,特别修改密码,和忘记密码这一块已经和以前完全不一样了。

一、 忘记密码

1、 在my.cnf 文件中添加skip-grant-tables,然后systemctl restart mysqld
2、 直接mysql 登录,此时不需要填写密码。
3、 update mysql.user set authentication_string=’’ where user=’root’ 清空root用户密码。
4、 注释掉skip-grant-tables,重启mysql
5、 mysql -uroot 无密码登录到root模式。
6、 select user,host from user where user='root';

7、 alter user ‘root@’localhost’ identified by ‘password’;
8、 flush privileges; 刷新权限

二、 修改密码
见上边第7步

三、 远程登录
1、 select user,host from mysql.user where user='user'; 查找用户名的登录状态

2、 修改host登录主机update mysql.user set host='%' where user='root';
%:表示所有主机可以登录,可以更改为ip地址
3、 查看权限

4、 flush privileges; 刷新权限

猜你喜欢

转载自www.cnblogs.com/simendavid/p/12930772.html