- 目的:
使用root 权限对新建的普通用户man1 进行密码的修改,原密码为1234,希望修改为12345
- mysql版本:8.0.25
最终代码:
set password for 'man1'@'localhost'='12345';
- 遇到的问题:
从最开始到最后成功的过程
-
select user,password from mysql.user;
ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’
这是因为8.0版本的mysql更新了,在user表里面没有password字段了,取而代之的是 authentication_string字段存的密码密文 -
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()等等 -
update user set authentication_string=MD5(‘12345’) where user=‘man2’;
ERROR 1046 (3D000): No database selected -
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加密后的值,和其他的密码密文形式不同
-
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,也登陆不上,报错同上。 -
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,结果是不存在这个函数的。 -
alter user ‘man2’@‘localhost’ identified with mysql_native_password by ‘123456’;
ERROR 1396 (HY000): Operation ALTER USER failed for ‘man2’@‘localhost’
百度了许多,发现新版本的修改密码发生了较大改变,尝试了网络上非常多的重复的帖子的推荐代码,提示错误如上。目前猜测是:该命令是用来修改root用户密码的,不能修改普通用户密码?没有细致探究原因 -
set password for man2@‘localhost’ = ‘12345’;
ERROR 1133 (42000): Can’t find any matching row in the user table
和最终成功的命令是一样的,目前猜测可能是由于之前的操作把man2用户的密码弄乱了或者是因为没有加引号,应为’man2‘@’localhost‘ -
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的错误提示 -
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用户已经被我玩烂了或者就是因为这个命令不行 -
最后的最后,我使用新的用户man1, 使用文章开始时就提到的那个命令,我成功了。耗时约3小时搜索加尝试才获得成功…