mysql 修改用户密码 普通用户 8.0.25版本

  • 目的:
    使用root 权限对新建的普通用户man1 进行密码的修改,原密码为1234,希望修改为12345
  • mysql版本:8.0.25

最终代码:
set password for 'man1'@'localhost'='12345';
在这里插入图片描述

  • 遇到的问题:
    从最开始到最后成功的过程
  1. select user,password from mysql.user;
    ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’在这里插入图片描述
    这是因为8.0版本的mysql更新了,在user表里面没有password字段了,取而代之的是 authentication_string字段存的密码密文

  2. update mysql.user set authentication_string=password(‘12345’) where user=‘man2’;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(‘12345’) where user=‘man2’’ at line 1在这里插入图片描述
    这是因为新版本也取消了password()这个加密函数,取而代之的有MD5(),SHA1(),SHA2()等等

  3. update user set authentication_string=MD5(‘12345’) where user=‘man2’;
    ERROR 1046 (3D000): No database selected

  4. update mysql.user set authentication_string=MD5(‘12345’) where user=‘man2’;
    Query OK, 1 row affected (0.10 sec)
    Rows matched: 1 Changed: 1 Warnings: 0
    在这里插入图片描述
    好像运行成功了,但是我在后面尝试登录的时候使用密码12345登录不上
    再次使用原密码1234,能够登录…
    select user,authentication_string from mysql.user; 之后结果里面是个md5加密后的值,和其他的密码密文形式不同
    在这里插入图片描述

  5. update mysql.user set authentication_string=SHA1(‘12345’) where user=‘man2’;
    Query OK, 1 row affected (0.36 sec)
    Rows matched: 1 Changed: 1 Warnings: 0
    在这里插入图片描述
    继之前使用md5加密尝试后新密码还是登录不上,我再次尝试了sha1加密方式,没有报错。
    但是,使用新密码12345登录不上,报错:
    ERROR 1045 (28000): Access denied for user ‘man2’@‘localhost’ (using password: YES)
    再次使用原密码1234,也登陆不上,报错同上。

  6. update mysql.user set authentication_string=caching_sha2_password(‘12345’) where user=‘man2’;
    ERROR 1305 (42000): FUNCTION mysql.caching_sha2_password does not exist
    在这里插入图片描述
    看到说新版本的加密方式是caching_sha2_password,结果是不存在这个函数的。

  7. alter user ‘man2’@‘localhost’ identified with mysql_native_password by ‘123456’;
    ERROR 1396 (HY000): Operation ALTER USER failed for ‘man2’@‘localhost’
    在这里插入图片描述
    百度了许多,发现新版本的修改密码发生了较大改变,尝试了网络上非常多的重复的帖子的推荐代码,提示错误如上。目前猜测是:该命令是用来修改root用户密码的,不能修改普通用户密码?没有细致探究原因

  8. set password for man2@‘localhost’ = ‘12345’;
    ERROR 1133 (42000): Can’t find any matching row in the user table
    在这里插入图片描述
    和最终成功的命令是一样的,目前猜测可能是由于之前的操作把man2用户的密码弄乱了或者是因为没有加引号,应为’man2‘@’localhost‘

  9. ALTER mysql.USER ‘man2’@‘localhost’ IDENTIFIED WITH caching_sha2_password BY ‘123456’;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘mysql.USER ‘man2’@‘localhost’ IDENTIFIED WITH caching_sha2_password BY ‘123456’’ at line 1
    在这里插入图片描述
    网上推荐的命令是:ALTER USER ‘man2’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
    这个报错的原因应该是我在user前面加上了mysql. 事实证明这是不需要且是错误的。同时我修改了后面的with参数,主要是因为8的错误提示

  10. mysqladmin -u man2@‘localhost’ -p ‘1234’ ‘12345’;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘mysqladmin -u man2@‘localhost’ -p ‘1234’ ‘12345’’ at line 1
    在这里插入图片描述
    当我看到了一个帖子,再次尝试新方法,失败。可能是因为我的man2用户已经被我玩烂了或者就是因为这个命令不行

  11. 最后的最后,我使用新的用户man1, 使用文章开始时就提到的那个命令,我成功了。耗时约3小时搜索加尝试才获得成功…

留此贴纪念,并供大家参考

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值