首页 > 数据库 >mysql.user表的数据准确性问题

mysql.user表的数据准确性问题

时间:2024-08-20 14:27:18浏览次数:7  
标签:set reuse 准确性 user mysql lifetime password

mysql.user这个系统表中有些字段的数据是不准确的(或者说是不一定准确,这样表达更严谨一点)。这是一个让人头疼的问题,下面简单述说一下问题,主要是mysql.user表中的password_lifetime,password_reuse_history,password_reuse_time这几个字段的数据都不一定准确。

下面简单演示一下,当前测试环境为MySQL 8.0.35。

mysql> show global variables like 'default_password_lifetime';
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| default_password_lifetime | 180   |
+---------------------------+-------+
1 row in set (0.00 sec)

mysql> show  global variables like 'password_history';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| password_history | 6     |
+------------------+-------+
1 row in set (0.01 sec)

mysql> show global variables like 'password_reuse_interval';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| password_reuse_interval | 365   |
+-------------------------+-------+
1 row in set (0.00 sec)

mysql>

此时,如果我创建一个用户test,如下所示,你会看到password_lifetime值为null,password_reuse_history的值为null,这个值明显不正确,是不是Bug呢?

mysql> CREATE USER `test`@`192.168.7.10%` IDENTIFIED BY  'Kjdh#234289dj';
Query OK, 0 rows affected (0.03 sec)

mysql> select user
    ->       ,host
    ->       ,account_locked 
    ->       ,password_last_changed
    ->       ,password_expired
    ->       ,password_lifetime
    ->       ,plugin 
    ->       ,password_reuse_history
    ->       ,Password_reuse_time
    -> from mysql.user
    -> where user='test'\G
*************************** 1. row ***************************
                  user: test
                  host: 192.168.7.10%
        account_locked: N
 password_last_changed: 2024-08-20 11:05:39
      password_expired: N
     password_lifetime: NULL
                plugin: caching_sha2_password
password_reuse_history: NULL
   Password_reuse_time: NULL
1 row in set (0.01 sec)

mysql> 

搜索相关资料时,发现已经有人反馈这个问题了,Bug #112128 The parameters such as MySQL password_history does not take effect[1] 但是官方的解释是这是一个"正常现象",它不是一个Bug,具体解释如下所示:

The way it works is as follows:
1. There is the global system variable default_password_lifetime that specifies the policy for all accounts that are set to use the default password lifetime. This is done by ALTER USER PASSWORD EXPIRE DEFAULT. In the system table (not that it matters, but still) this stores a NULL. The NULL value is used as a flag that the account in question does not have a special per user password lifetime. The special per-user password lifetime is set via ALTER USER PASSWORD EXPIRE NEVER (which sets the column to 0) or ALTER USER PASSWORD EXPIRE INTERVAL N DAY (which sets the column to N). 
As a consequence all password lifetimes for all users that do not have a specific password lifetime set will follow the value of the global variable.
And if you store a specific password lifefile for a user account it will "detach" itself from the global variable's value and will be pegged to whatever you've set for it. Until you reset it back to the default of course.

简单翻译如下:

它的工作原理如下:

有一个全局系统变量 default_password_lifetime,它指定了所有使用默认密码生命周期的帐户的策略。这是通过 ALTER USER PASSWORD EXPIRE DEFAULT命令完成的。在系统表中(这并不重要,但还是说一下),它存储了一个 NULL 值。NULL 值被用作一个标志,表示相关的帐户没有特别的用户密码生命周期。 每个用户的特殊的密码生命周期是通过 ALTER USER PASSWORD EXPIRE NEVER(这将列设置为 0)或 ALTER USER PASSWORD EXPIRE INTERVAL N DAY(这将列设置为 N)来设置的。 因此,所有没有设置特定/特殊密码生命周期的用户的所有密码生命周期都将遵循全局变量的值。 如果你为一个用户帐户存储了一个特定的密码生命周期,它将“脱离”全局变量的值,并被固定为你为它设置的任何值。当然,除非你将其重置回默认值。

搜索资料的过程,发现反馈这种现象("bug")的还不止一个,另外一个链接也是反馈了同样的问题,Bug #89349 password_lifetime set to Null for user after changing default_password_lifetime[2]

这里简单说明一下,就是mysql.user中,password_lifetime值为null,表示它使用全局系统变量的值,如果你为某个用户指定了 特殊的密码过期时间,那么mysql.user的password_lifetime字段才会存储特定的密码过期时间。也就是说如果我们创建用户的时候指定密码过期时间,或者使用SQL语句指定用户的密码过期时间,此时mysql.user中的password_lifetime等字段值就是正确的。如下所示

mysql> ALTER USER 'test'@'192.168.7.10%' PASSWORD EXPIRE INTERVAL 60 DAY;
Query OK, 0 rows affected (0.01 sec)

mysql> select user
    ->       ,host
    ->       ,account_locked 
    ->       ,password_last_changed
    ->       ,password_expired
    ->       ,password_lifetime
    ->       ,plugin 
    ->       ,password_reuse_history
    ->       ,Password_reuse_time
    -> from mysql.user
    -> where user='test'\G
*************************** 1. row ***************************
                  user: test
                  host: 192.168.7.10%
        account_locked: N
 password_last_changed: 2024-08-20 11:05:39
      password_expired: N
     password_lifetime: 60
                plugin: caching_sha2_password
password_reuse_history: NULL
   Password_reuse_time: NULL
1 row in set (0.00 sec)

mysql> CREATE USER test1@'%' IDENTIFIED BY 'Kjdh#234289dj' 
    -> PASSWORD EXPIRE INTERVAL 20 DAY 
    -> PASSWORD HISTORY 30  
    -> PASSWORD REUSE INTERVAL 60 DAY;
Query OK, 0 rows affected (0.03 sec)

mysql> select user
    ->       ,host
    ->       ,account_locked 
    ->       ,password_last_changed
    ->       ,password_expired
    ->       ,password_lifetime
    ->       ,plugin 
    ->       ,password_reuse_history
    ->       ,Password_reuse_time
    -> from mysql.user
    -> where user='test1'\G
*************************** 1. row ***************************
                  user: test1
                  host: %
        account_locked: N
 password_last_changed: 2024-08-20 11:57:18
      password_expired: N
     password_lifetime: 20
                plugin: caching_sha2_password
password_reuse_history: 30
   Password_reuse_time: 60
1 row in set (0.00 sec)

mysql>
参考资料
[1]

1: https://bugs.mysql.com/bug.php?id=112128

[2]

2: https://bugs.mysql.com/bug.php?id=89349

标签:set,reuse,准确性,user,mysql,lifetime,password
From: https://www.cnblogs.com/kerrycode/p/18369382

相关文章

  • 在Python中使用MySQL:保姆级指南
    Python是一种广泛使用的高级编程语言,因其简洁易读以及强大的库支持而受到开发者的青睐。当需要在Python程序中处理数据库时,MySQL是一个流行的选择。MySQL是一个开源的关系数据库管理系统,广泛用于Web应用程序的开发。目录第一步:安装MySQL数据库第二步:安装MySQLConnector第......
  • Centos 7.9系统 源码安装MySQL5.7版本
    mysql5.7安装详细一、MySQL5.7源码安装部署1.1安装环境准备相关依赖包的作用:cmake:由于从MySQL5.5版本开始弃用了常规的configure编译方法,所以需要CMake编译器,用于设置mysql的编译参数,如:安装目录、数据存放目录、字符编码、排序规则等。boost库:从MySQL5.7.5开......
  • MySQL5.7 用户设置密码解决方法
    1:执行修改用户的密码时,一直报错:即修改密码命令:mysql>alteruser'root'@'localhost'identifiedby'123456';报错如下:mysql>alteruser'root'@'localhost'identifiedby'123456';ERROR1396(HY000):OperationALTE......
  • MySQL编译安装-麒麟V10 x86
    环境信息操作系统:KylinLinuxAdvancedServerV10(Sword)架构:X86MySQL版本:5.7.44编译安装必要的依赖库和编译工具sudoyumgroupinstall'DevelopmentTools'sudoyuminstallcmakencurses-developenssl-develboost-devel下载MySQL源码从MySQL官方网站......
  • Centos 7.9系统 源码安装MySQL8.0
    1.编译安装1.1下载编译所需包#检查重复包、卸载rpm-qa|grepmariadb*|xargsrpm-e--nodeps#下载所需软件包cd/usr/local/src/wgethttps://mirrors.ustc.edu.cn/gnu/gmp/gmp-6.1.2.tar.xzwgethttps://mirrors.ustc.edu.cn/gnu/mpfr/mpfr-4.0.2.tar.gzwget......
  • 基于PHP+MySQL组合开发的DIY分销商城小程序源码系统 附带源代码包以及搭建部署教程
    系统概述随着消费者对购物便捷性、个性化需求的不断增长,传统的电商模式已难以满足市场多样化需求。分销商城小程序以其低门槛、易传播、高粘性等特点,成为众多商家转型升级的首选。本源码系统正是基于这一市场需求,利用PHP这一成熟稳定的后端开发语言和MySQL数据库,结合微信小程......
  • EOFException com.mysql.cj.protocol.FullReadInputStream in readFully
    背景:mysql查询性能瓶颈,一般前提有很多查询超时导致这个问题java.io.EOFException:Cannotreadresponsefromserver.Expectedtoread4bytes,read0bytesbeforeconnectionwasunexpectedlylost.atcom.mysql.cj.protocol.FullReadInputStream.readFully(FullRe......
  • show processlist查看Mysql当前正在运行的线程
    showprocesslistshowprocesslist;--或者SELECTid,db,user,host,command,time,state,infofrominformation_schema.PROCESSLISTWHERE1=1--andcommand!='Sleep'ANDHOSTLIKE'%localhost%'orderbytimedescID定义:每个连......
  • gpt给的user-agent集合
    以下是一些常见的User-Agent字符串,分为不同的浏览器和操作系统类型,可以根据你的需求进行选择或修改:浏览器User-Agent字符串ChromeMozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/114.0.5735.199Safari/537.36Mozilla/5.0(M......
  • 【MYSQL】在MySQL中设置 max_allowed_packet、wait_timeout 和 interactive_timeout
    目录重要配置参数临时设置参数1.使用SQL语句设置1.检查当前设置持久化设置修改配置文件在Linux上重启MySQL服务:在Windows上重启MySQL服务:注意事项示例:使用BLOB存储大数据总结解决连接断开问题的总结在处理大于1MB的数据时,MySQL数据库可能会遇到......