译文 | MySQL 8.0 密码管理策略(一)

MySQL 8.0 在密码管理方面有很多改善,本文将介绍以下两个特性。

  • 密码重用策略
  • 生成随机密码

简单地说,当您设置新密码时,您可以限制使用以前使用的密码。有两种策略:

[En]

To put it simply, when you set a new password, you can restrict the use of previously used passwords. There are two strategies:

  • 历史密码 password_history
  • 间隔时间 password_reuse_interval

1.1 历史密码

MySQL 官方手册描述:

If an account is restricted on the basis of number of password changes, a new password cannot be chosen from a specified number of the most recent passwords.

在实验环境中,创建用户并添加条件 password history 2,历史密码中最近的两个不能被重新使用。

mysql> create user 'herc'@'localhost' identified by 'Percona@321' password history 2;
Query OK, 0 rows affected (0.02 sec)

mysql> select user, host, password_reuse_history from mysql.user where user='herc'\G
*************************** 1. row ***************************
                  user: herc
                  host: localhost
password_reuse_history: 2
1 row in set (0.00 sec)

MySQL 将在 mysql.password_history 表上记录密码更改的信息。

mysql> select * from mysql.password_history;
+-----------+------+----------------------------+------------------------------------------------------------------------+
| Host      | User | Password_timestamp         | Password                                                               |
+-----------+------+----------------------------+------------------------------------------------------------------------+
| localhost | herc | 2021-09-20 15:44:42.295778 | $A$005$=R:q'M(Kh#D];c~SdCLyluq2UVHFobjWOFTwn2JYVFDyI042sl56B7DCPSK5 |
+-----------+------+----------------------------+------------------------------------------------------------------------+
1 row in set (0.00 sec)

接下来我们尝试更改用户 herc@localhost 的密码。

mysql> alter user 'herc'@'localhost' identified by 'MySQL@321';
Query OK, 0 rows affected (0.02 sec)

mysql> select * from mysql.password_history\G
*************************** 1. row ***************************
              Host: localhost
              User: herc
Password_timestamp: 2021-09-20 15:49:15.459018
CGeRQT31UUwtw194KOKGdNbgj3558VUB.dxcoS8r4IKpG8
*************************** 2. row ***************************
              Host: localhost
              User: herc
Password_timestamp: 2021-09-20 15:44:42.295778
          Password: $A$005$=R:q'M(Kh#D];c~SdCLyluq2UVHFobjWOFTwn2JYVFDyI042sl56B7DCPSK5
2 rows in set (0.00 sec)

更改成功后,查看 mysql.password_history 表,可见该表存有最近两个密码的信息。

再次更改该用户密码,且密码为创建用户时设置的密码值(Percona@321)。

mysql> alter user 'herc'@'localhost' identified by 'Percona@321';
ERROR 3638 (HY000): Cannot use these credentials for 'herc@localhost' because they contradict the password history policy

修改失败! 因为根据我们设置的限制策略,不能重用在 mysql.password_policy 表中被记录的最近的两个密码。因此,如果想再次重复使用第一个密码,就不能让该密码出现在 mysql.password_policy 表中。

再设置一个新密码后(第一个密码已经不是最近的两个密码了),再尝试用第一个密码值(Percona@321)进行修改, 修改成功!

mysql> alter user 'herc'@'localhost' identified by 'Herc@321';
Query OK, 0 rows affected (0.01 sec)

mysql> alter user 'herc'@'localhost' identified by 'Percona@321';
Query OK, 0 rows affected (0.02 sec)

也可以在启动时在全局配置 password_history

#vi my.cnf
[mysqld]
password_history=6

#set global
mysql> set global password_history=5;
Query OK, 0 rows affected (0.00 sec)

1.2 间隔时间

MySQL 官方手册描述:

If an account is restricted based on time elapsed, a new password cannot be chosen from passwords in the history that are newer than a specified number of days.

测试前,创建了用户 sri@localhost,并设置用户密码可重用的时间间隔为五天。

mysql> create user 'sri'@'localhost' identified by 'Percona@321' password reuse interval 5 day;
Query OK, 0 rows affected (0.01 sec)

mysql> select user, host, password_reuse_time from mysql.user where user='sri'\G
*************************** 1. row ***************************
               user: sri
               host: localhost
password_reuse_time: 5
1 row in set (0.00 sec)

这意味着,每个密码在生效后五天内不能重复设置。

[En]

This means that each password cannot be set repeatedly for five days after it takes effect.

mysql> select * from mysql.password_history where user='sri'\G
*************************** 1. row ***************************
              Host: localhost
              User: sri
Password_timestamp: 2021-09-20 16:09:27.918585
          Password: $A$005$+B   e3!C9&8m
                                         eFRG~IqRWX4b6PtzLA8I4VsdYvWU3qRs/nip/QRhXXR5phT6
1 row in set (0.00 sec)

执行 ALTER 来更改密码。

mysql> alter user 'sri'@'localhost' identified by 'Herc@321';
Query OK, 0 rows affected (0.02 sec)

mysql> select * from mysql.password_history where user='sri'\G
*************************** 1. row ***************************
              Host: localhost
              User: sri
Password_timestamp: 2021-09-20 16:17:51.840483
          Password: $A$005$~k7qp8.OP=^#e79qwtiYd7/cmCFLvHM7MHFbvfX2WlhXqzjmrN03gGZ4
*************************** 2. row ***************************
              Host: localhost
              User: sri
Password_timestamp: 2021-09-20 16:09:27.918585
          Password: $A$005$+B   e3!C9&8m
                                         eFRG~IqRWX4b6PtzLA8I4VsdYvWU3qRs/nip/QRhXXR5phT6
2 rows in set (0.00 sec)

现在再次尝试将其设置为第一个密码。

[En]

Now try setting it to the first password again.

mysql> alter user 'sri'@'localhost' identified by 'Percona@321';
ERROR 3638 (HY000): Cannot use these credentials for 'sri@localhost' because they contradict the password history policy

设置失败!

也可以在启动时在全局配置 password_reuse_interval

#vi my.cnf
[mysqld]
password_reuse_interval=365

#set global
mysql> set global password_reuse_interval=365;
Query OK, 0 rows affected (0.00 sec)

从 MySQL 8.0.18 开始,MySQL 能够为用户帐户创建随机密码。这意味着可以不必分配指定密码。它支持以下语句:

  • 创建用户
  • 更改用户
  • 设置密码

我们需要使用 RANDOM PASSWORD 以避免修改密码时屏幕上有明文显示。例如:

mysql> create user 'sakthi'@'localhost' identified by random password;
+--------+-----------+----------------------+
| user   | host      | generated password   |
+--------+-----------+----------------------+
| sakthi | localhost | .vZYy+<<bo7l1;vtiufh 1 | +--------+-----------+----------------------+ row in set (0.01 sec) mysql> alter user 'sri'@'localhost' identified by random password;
+------+-----------+----------------------+
| user | host      | generated password   |
+------+-----------+----------------------+
| sri  | localhost | 5wb>2[]q*jbDsFvlN-i_ |
+------+-----------+----------------------+
1 row in set (0.02 sec)
</bo7l1;vtiufh>

密码哈希值将存储在 mysql.user 表中。

mysql> select user, authentication_string from mysql.user where user in ('sakthi','sri')\G
*************************** 1. row ***************************
                 user: sakthi
authentication_string: $A$005$L`PYcedj%3tz*J>ioBP1.Rsrj7H8wtelqijvV0CFnXVnWLNIc/RZL0C06l4oA
*************************** 2. row ***************************
                 user: sri
authentication_string: $A$005$/k?aO&ap.#b=
                                          ^zt[E|x9q3w9uHn1oEumXUgnqNMH8xWo4xd/s26hTPKs1AbC2
2 rows in set (0.00 sec)

默认情况下,密码长度为 20 个字符。我们可以使用变量 generated_random_password_length 定义密码长度,允许的长度范围是 5 到 255。

mysql> select @@generated_random_password_length;
+------------------------------------+
| @@generated_random_password_length |
+------------------------------------+
|                                 20 |
+------------------------------------+
1 row in set (0.00 sec)

如果 validate_password 组件已经安装,对随机密码策略不会有影响。

还有一些特性将在下一篇文章中介绍。

[En]

There are also some features that will be introduced in the next article.

MySQL 手册:

Original: https://www.cnblogs.com/radondb/p/15351916.html
Author: RadonDB
Title: 译文 | MySQL 8.0 密码管理策略(一)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/508094/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 使用Ant从零开始搭建tomcat源码环境

    使用Ant从零开始搭建tomcat源码环境 视频教程 准备工作 编辑 Idea,且装上Checkstyle插件(或者其他开发工具) 编译依赖的Jar包. 开始搭建 搭建编译环境 安…

    数据库 2023年6月11日
    0100
  • 生产数据库主键超出限制解决方案

    不说那种建表的时候 设置好主键格式 的 解决方案. 事后诸葛啊. 谁都会 不靠谱方案1改主键表结构. 费时! 主键已经超长了.说明 数据量相当大. 改表结构的时间成本你能等得起吗方…

    数据库 2023年6月14日
    086
  • vue导入UEditor报错问题分析

    直接上报错信息,如下。。。。 1.看看js是否导入 2.看看ue是否加入 F12 控制台输入则可看见那就是导入了,不是这个问题。 在查看问题的目标方向……….

    数据库 2023年6月6日
    0131
  • cobbler

    cobbler 1. cobbler简介 2. cobbler服务端部署 cobbler简介 Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速…

    数据库 2023年6月14日
    074
  • 安装Pycharm2022.2.1版本操作说明

    下载pycharm:https://www.jetbrains.com.cn/pycharm/download/#section=windows 我下载的是社区版”Co…

    数据库 2023年6月14日
    0161
  • Redis 使用的 10 个小技巧

    Redis 在当前的技术社区里是非常热门的。从来自 Antirez 一个小小的个人项目到成为内存数据存储行业的标准,Redis已经走过了很长的一段路。 随之而来的一系列最佳实践,使…

    数据库 2023年6月9日
    073
  • Celery异步任务

    (1)安装celery pip install celery==4.2.1 (2)celery使用 在项目适当位置创建celery_tasks目录用于保存celery异步任务。 在…

    数据库 2023年6月14日
    076
  • Linux 下安装 redis

    2、使用命令下载: 3、将文件拷贝到安装目录 /usr/local 目录下 4、进入 /usr/local 目录下,解压安装包 5、进入解压后的目录 6、编译,将 redis 安装…

    数据库 2023年6月14日
    091
  • PDF转换OFD(Java实用版)

    前言: 在项目中用到了,就写一下哈 OFD简介 百度百科:https://baike.baidu.com/item/OFD/56227163?fr=aladdin OFD(Open…

    数据库 2023年6月16日
    0132
  • Redis学习

    Redis 因为没有指定配置文件 需配置 redis-server redis.windows.conf 之后自动启动 测试性能 redis-benchmark -p 6379 -…

    数据库 2023年6月16日
    077
  • mysql中group by,having,order by,limit,distinct的用法和简单的的多表查询

    group:组 by:通过 group by :通过….。分组group by列名:通过指定列来分组 一般情况下在题目中出现 “每个” &#82…

    数据库 2023年6月16日
    0116
  • 如何基于LSM-tree架构实现一写多读

    PolarDB是阿里巴巴自研的新一代云原生关系型数据库,在存储计算分离架构下,利用了软硬件结合的优势,为用户提供具备极致弹性、海量存储、高性能、低成本的数据库服务。X-Engine…

    数据库 2023年5月24日
    075
  • 滑动窗口

    滑动窗口,记录左边界,通过map避免字符重复。 class Solution { public int lengthOfLongestSubstring(String s) { i…

    数据库 2023年6月11日
    075
  • 详解apollo的设计与使用

    apollo 是一款由携程团队开发的配置中心,可以实现配置的集中管理、分环境管理、即时生效等等。在这篇博客中,我们可以了解到: 这里我回答的是为什么使用配置中心,而不是为什么使用 …

    数据库 2023年6月6日
    097
  • 2022的七夕,奉上7个精美的表白代码,同时教大家快速改源码自用

    🤵‍♂️ 个人主页:奇想派👨‍💻 作者简介:奇想派,十年全栈开发经验,团队负责人。喜欢钻研技术,争取成为编程达人 🎖️!🗺️学海无涯苦作舟,🛤️编程之路无悔路!📝 如果文章对你有帮…

    数据库 2023年6月16日
    0108
  • RadonDB MySQL on K8s 2.1.2 发布!

    RadonDB MySQL on Kubernetes 于 2 月 17 日发布了新版本 2.1.2 。该版本在节点的重建、增删等方面进行了全面升级。致谢: 首先感谢 @andyl…

    数据库 2023年5月24日
    076
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球