MySQL的配置文件my.cnf中配置默认的密码认证插件的方式如下:
[mysqld]
default_authentication_plugin=mysql_native_password
# 或者下面的使用sha256_password作为默认的密码认证插件
# default_authentication_plugin=sha256_password
IDENTIFIED WITH auth_plugin
如果我们要修改某一个用户的密码认证插件,就可以使用到IDENTIFIED WITH auth_plugin这个语句了 。如果一个用户它的密码认证插件使用的是默认的mysql_native_password,我们想把它的密码认证插件修改为sha256_password,此时我们就可以使用下面的命令来修改:
alter user xyz identified with sha256_password;
执行完成上述命令后,xyz这个用户的密码就会设置为空,并更新它的密码为已经过期,同时更新了它的密码认证插件为sha256_password,结果如下所示:
mysql> select user, host, plugin, authentication_string, password_expired from mysql.user where user ='xyz';
+——+——+———————–+——————————————-+——————+
| user | host | plugin| authentication_string| password_expired |
+——+——+———————–+——————————————-+——————+
| xyz| %| mysql_native_password | *39C549BDECFBA8AFC3CE6B948C9359A0ECE08DE2 | N|
+——+——+———————–+——————————————-+——————+
1 row in set (0.03 sec)
mysql> alter user xyz identified with sha256_password;
Query OK, 0 rows affected (0.02 sec)
mysql> select user, host, plugin, authentication_string, password_expired from mysql.user where user ='xyz';
+——+——+—————–+———————–+——————+
| user | host | plugin| authentication_string | password_expired |
+——+——+—————–+———————–+——————+
| xyz| %| sha256_password || Y|
+——+——+—————–+———————–+——————+
1 row in set (0.02 sec)
mysql>
更改用户的密码认知方式之后,当xyz再次尝试登录MySQL数据库的时候,输入空密码登录成功后,会要求其修改一下自己的密码,然后才可以执行其他SQL语句的操作,这个要求和我们刚安装MySQL数据库后,第一次使用root登录的时候要求修改root的密码是一样的 。下面是修改完成用户xyz的密码认证插件之后,尝试使用空密码登录后的操作示例:
?Downloads mysql -uxyz -p -h10.2.1.7
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \\g.
Your MySQL connection id is 45197703
Server version: 5.7.25-log
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.
mysql> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. # 这里提示需要修改完成密码之后才可以执行其他SQL语句命令 。
推荐阅读
- 炉石传说怎么改密码 炉石传说修改密码
- 天姬变怎么修改元宝 天姬变元宝修改器
- ppt背景颜色怎么统一修改 ppt背景颜色
- 图片怎么修改尺寸 图片怎么修改尺寸
- qq安全中心怎么修改实名认证
- 怎么修改苹果id密码
- 如何修改主页
- 手机信号屏蔽怎么办
- 怎样修改手机号服务密码
- 修改唇形 其实就是这么简单
