MySQL如何实现用户密码过期性能
发布时间:2021-12-26 00:57:24 所属栏目:MySql教程 来源:互联网
导读:这篇文章主要介绍了MySQL如何实现用户密码过期功能,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。 从MySQL版本5.6.6版本起,添加了password_expired功能,它允许设置用户的过期时间。
这篇文章主要介绍了MySQL如何实现用户密码过期功能,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。 从MySQL版本5.6.6版本起,添加了password_expired功能,它允许设置用户的过期时间。 这个特性已经添加到mysql.user数据表,但是它的默认值是”N”。可以使用ALTER USER语句来修改这个值。 例如: mysql> ALTER USER mdba@'localhost' PASSWORD EXPIRE; Query OK, 0 rows affected (0.04 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) 在MySQL 5.7.8版开始用户管理方面添加了锁定/解锁用户账户的新特性 例如: mysql> alter user mdba@localhost account lock; Query OK, 0 rows affected (0.04 sec) 重新登录发现被拒绝: [root@localhost ~]# mysql -u mdba -p Enter password: ERROR 3118 (HY000): Access denied for user 'mdba'@'localhost'. Account is locked. 解锁后恢复正常: mysql> alter user mdba@localhost account unlock; Query OK, 0 rows affected (0.03 sec) [root@localhost ~]# mysql -u mdba -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 942539 Server version: 5.7.17-debug-log Source distribution Copyright (c) 2000, 2016, 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> 从MySQL 5.7.4版开始,用户的密码过期时间这个特性得以改进,可以通过一个全局变量default_password_lifetime来设置密码过期的策略, 此全局变量可以设置一个全局的自动密码过期策略。 在MySQL5.7的配置文件中设置一个默认值,这会使得所有MySQL用户的密码过期时间都为90天,MySQL会从启动时开始计算时间。 例如在my.cnf里添加: [mysqld] default_password_lifetime=90 这会使得所有MySQL用户的密码过期时间都为90天,MySQL会从启动时开始计算时间。 如果要设置密码永不过期的全局策略,可以设置default_password_lifetime=0,或者在命令行设置: mysql> SET GLOBAL default_password_lifetime = 0; Query OK, 0 rows affected (0.00 sec) 感谢你能够认真阅读完这篇文章,希望小编分享的“MySQL如何实现用户密码过期功能”这篇文章对大家有帮助。 (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |