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;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


按照以下操作执行完后此用户的所有操作就又会被允许执行:

mysql>  alter user mdba@localhost identified by 'Aisino123!';
Query OK, 0 rows affected (0.03 sec)


mysql> flush privileges;
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)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2135972/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2135972/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值