打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Mysql—修改用户密码(重置密码)

1、登录mysql

[root@localhost ~]# mysql -uroot -p123456
[root@localhost ~]# mysql -hlocalhost -uroot -p123456

如果忘记密码,则跳过MySQL的密码认证过程。步骤如下:

  • 修改Mysql配置文件:vi /etc/my.cnf(注:windows下修改的是my.ini)。在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程。
  • 重启Mysql:
  • 进入Mysql:[root@localhost ~]# mysql -uroot -p

2、使用mysql数据库,从user表中查看主机,用户名,密码

-- 使用mysql数据库
mysql> use mysql;
-- 查询主机用户名密码:5.7版本之前的
mysql> select host,user,plugin,password from user;
-- 查询主机用户名密码:5.7版本之后的,包括5.7
mysql> select host,user,plugin,authentication_string from user;
mysql> select host,user,plugin,authentication_string from user\G;
mysql> select host,user,plugin,authentication_string from mysql.user;

3、修改密码,刷新一下权限

mysql> update user set password=password("新密码") where user="root";
mysql> flush privileges;
mysql> quit

上面修改密码是在5.7版本之前的。若是5.7版本之后的(包括5.7),没有password这个字段了,则修改方法如下:

mysql> alter user "root"@"localhost" identified by "新密码";  --方法1
mysql> update user set authentication_string=password("新密码") where user="root";  -- 方法2
mysql> flush privileges;
mysql> quit

4、如果以上不能解决密码修改,则使用下面方法

mysql> use mysql;
mysql> alter user "root"@"localhost" identified with mysql_native_password by "新密码";
mysql> flush privileges;

修改加密规则:mysql> alter user "root"@"localhost" identified by 'password' PASSWORD EXPIRE NEVER; 

如果执行以上的操作并没有解决,请再把default_authentication_plugin=mysql_native_password添加到配置中。

5、再去编辑一下my.cnf配置文件,去掉skip-grant-tables。

6、重启Mysql,用你修改后的密码登录Mysql。

  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
MySQL 第三方的客户端连不上数据库,Authentication plugin 'caching
Mysql 解决1251- Client does not support authentication protocol requested by server...的问题
mysql出现ERROR1698(28000):Access denied for user root@localhost错误解决方法
mysql修改密码方法
修改Docker容器内的MySQL服务密码,并成功完成可视化工具登录【绝对有效】
Linux CentOS7系统 mysql 8.0.19:安装
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服