Payment Card Industry,即支付卡行业,PCI行业表示借记卡、信用卡、预付卡、电子钱包、ATM和POS卡及相关的业务。
PCI DSS,即PCI数据安全标准(Payment Card Industry Data Security Standard)是由PCI安全标准委员会制定,旨在使国际上采用一致的数据安全措施。java
PCI DSS标准要求用户每隔90天必须更改他们的密码。那么MySQL数据库该怎样适应这个状况?幸运的是,在MySQL版本5.6.6版本起,添加了password_expired功能,它容许设置用户的过时时间。mysql
这个特性已经添加到mysql.user数据表,可是它的默认值是”N”。可使用ALTER USER语句来修改这个值。sql
下面是关于如何设置MySQL用户帐号的到期日期一个简单例子:数据库
1
|
mysql>
ALTER
USER
'testuser'
@
'localhost'
PASSWORD
EXPIRE;
|
一旦某个用户的这个选项设置为”Y”,那么这个用户仍是能够登录到MySQL服务器,可是在用户未设置新密码以前不能运行任何查询语句,并且会获得以下错误消息提示:安全
1
2
3
|
mysql> SHOW DATABASES;
ERROR 1820 (HY000): You must
SET
PASSWORD
before executing this statement
Keep
in
mind that this does
not
affect
any
current
connections the account has
open
.
|
当用户设置了新密码后,此用户的全部操做(根据用户自身的权限)会被容许执行:服务器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
mysql>
SET
PASSWORD
=
PASSWORD
(
'mechipoderranen'
);
Query OK, 0
rows
affected (0.00 sec)
mysql> SHOW DATABASES;
+
--------------------+
|
Database
|
+
--------------------+
| information_schema |
| data |
| logs |
| mysql |
| performance_schema |
| test |
+
--------------------+
6
rows
in
set
(0.00 sec)
mysql>
|
DBA能够经过cron定时器任务来设置MySQL用户的密码过时时间。学习
从MySQL 5.7.4版开始,用户的密码过时时间这个特性得以改进,能够经过一个全局变量default_password_lifetime来设置密码过时的策略,此全局变量能够设置一个全局的自动密码过时策略。this
用法示例:
能够在MySQL的配置文件中设置一个默认值,这会使得全部MySQL用户的密码过时时间都为90天,MySQL会从启动时开始计算时间。my.cnf配置以下:spa
1
2
|
[mysqld]
default_password_lifetime=90
|
若是要设置密码永不过时的全局策略,能够这样:(注意这是默认值,配置文件中能够不声明).net
1
2
|
[mysqld]
default_password_lifetime=0
|
在MySQL运行时可使用超级权限修改此配置:
1
2
|
mysql>
SET
GLOBAL
default_password_lifetime = 90;
Query OK, 0
rows
affected (0.00 sec)
|
还可使用ALTER USER命令为每一个具体的用户帐户单独设置特定的值,它会自动覆盖密码过时的全局策略。要注意ALTER USER语句的INTERVAL的单位是“天”。
1
|
ALTER
USER
‘testuser
'@‘localhost'
PASSWORD
EXPIRE INTERVAL 30
DAY
;
|
禁用密码过时:
1
|
ALTER
USER
'testuser'
@
'localhost'
PASSWORD
EXPIRE NEVER;
|
让用户使用默认的密码过时全局策略:
1
|
ALTER
USER
'testuser'
@
'localhost'
PASSWORD
EXPIRE
DEFAULT
;
|
从MySQL 5.7.6版开始,还可使用ALTER USER语句修改用户的密码:
1
2
|
mysql>
ALTER
USER
USER
() IDENTIFIED
BY
'637h1m27h36r33K'
;
Query OK, 0
rows
affected (0.00 sec)
|
后记
在MySQL 5.7.8版开始用户管理方面添加了锁定/解锁用户帐户的新特性, related to user management is locking/unlocking user accounts when CREATE USER, or at a later time running the ALTER USER statement.
下面建立一个带帐户锁的用户:
1
2
|
mysql> CREATE USER
'furrywall'
@
'localhost'
IDENTIFIED BY
'71m32ch4n6317'
ACCOUNT LOCK;
Query OK,
0
rows affected (
0.00
sec)
|
以下所示,新建立的用户在尝试登录时会获得一个ERROR 3118错误消息提示:
1
2
3
|
$ mysql -ufurrywall -p
Enter password:
ERROR
3118
(HY000): Access denied
for
user
'furrywall'
@
'localhost'
. Account is locked.
|
此时就须要使用ALTER USER … ACCOUNT UNLOCK语句进行解锁了:
1
2
|
mysql>ALTER USER
'furrywall'
@
'localhost'
ACCOUNT UNLOCK;
Query OK,
0
rows affected (
0.00
sec)
|
如今,这个用户已经解锁,能够登录了:
1
2
3
4
5
6
7
8
9
10
11
|
$ mysql -ufurrywall -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is
17
Server version:
5.7
.
8
-rc MySQL Community Server (GPL)
Copyright (c)
2000
,
2015
, 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>
|
还能够这样锁定用户帐户:
1
2
|
mysql> ALTER USER
'furrywall'
@
'localhost'
ACCOUNT LOCK;
Query OK,
0
rows affected (
0.00
sec)
|
以上就是为你们介绍的MySQL的用户密码过时功能的相关内容,但愿对你们的学习有所帮助。