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的用戶密碼過時功能的相關內容,但願對你們的學習有所幫助。