【问题标题】:Do we need to run flush privileges after changing variable default_password_lifetime in MySQL?在 MySQL 中更改变量 default_password_lifetime 后是否需要运行刷新权限?
【发布时间】:2017-05-17 05:35:06
【问题描述】:

MySQL 在 MySQL-5.7 中有一个新变量,用于保存 mysql 用户的密码到期详细信息 - 特定用户的密码在多少天后到期。

此变量的详细信息:Doc

当我们更改此变量时,是否需要运行刷新权限,否则更改将立即对所有具有默认过期策略的用户生效?

【问题讨论】:

    标签: mysql database mysql-5.7


    【解决方案1】:

    根据文档,应该没有必要:

    6.3.6 Password Expiration Policy

    ...

    当客户端成功连接后,服务器会判断是否 帐号密码已过期:

    • 服务器检查密码是否已手动过期,如果是,则限制会话。

    • 否则,服务器会根据密码自动过期策略检查密码是否已过期。如果是这样的话, 服务器认为密码过期并限制会话。

    ...

    重要提示:更改仅对后续连接生效。

    这里是一个例子:

    $ mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 13
    Server version: 5.7.18
    
    Copyright (c) 2000, 2017, 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 @@GLOBAL.default_password_lifetime;
    +------------------------------------+
    | @@GLOBAL.default_password_lifetime |
    +------------------------------------+
    |                                  0 |
    +------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> CREATE USER 'johndoe'@'localhost'
        -> IDENTIFIED WITH mysql_native_password AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'
        -> PASSWORD EXPIRE DEFAULT;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit
    Bye
    
    $ mysql -u johndoe -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 14
    Server version: 5.7.18
    
    Copyright (c) 2000, 2017, 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 CURRENT_USER();
    +-------------------+
    | CURRENT_USER()    |
    +-------------------+
    | johndoe@localhost |
    +-------------------+
    1 row in set (0.00 sec)
    
    mysql> exit
    Bye
    
    $ mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 15
    Server version: 5.7.18
    
    Copyright (c) 2000, 2017, 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> SET @@GLOBAL.default_password_lifetime := 1;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> SELECT @@GLOBAL.default_password_lifetime;
    +------------------------------------+
    | @@GLOBAL.default_password_lifetime |
    +------------------------------------+
    |                                  1 |
    +------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT NOW();
    +---------------------+
    | NOW()               |
    +---------------------+
    | 2010-01-01 00:00:01 |
    +---------------------+
    1 row in set (0.00 sec)
    
    mysql> \! date -s "2010-01-02 $(date +%H:%M:%S)"
    Sat Jan 02 00:00:05 UTC 2010
    mysql> SELECT NOW();
    +---------------------+
    | NOW()               |
    +---------------------+
    | 2010-01-02 00:00:06 |
    +---------------------+
    1 row in set (0.01 sec)
    
    mysql> exit
    Bye
    
    $ mysql -u johndoe -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 16
    Server version: 5.7.18
    
    Copyright (c) 2000, 2017, 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 CURRENT_USER();
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    

    其他感兴趣的信息:

    【讨论】:

      【解决方案2】:

      我认为答案是否定的。

      因为default_password_lifetime是一个全局变量,其信息存储在information_schema.GLOBAL_VARAIBLES中,它是一个内存引擎表!

      在 mysql 中,flush 操作会导致缓冲区中的数据写回磁盘,只有在 MyISAM 引擎中才有必要;但是,flushprivilege 子句是将有关帐户和权限相关表的数据从磁盘 MyISAM 文件重新加载到内存中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-16
        • 2020-01-17
        • 1970-01-01
        • 2020-11-03
        相关资源
        最近更新 更多