這篇文章主要介紹了MySQL如何實(shí)現(xiàn)用戶密碼過期功能,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

從MySQL版本5.6.6版本起,添加了password_expired功能,它允許設(shè)置用戶的過期時(shí)間。
這個(gè)特性已經(jīng)添加到mysql.user數(shù)據(jù)表,但是它的默認(rèn)值是”N”。可以使用ALTER USER語句來修改這個(gè)值。
例如:
mysql> ALTER USER mdba@'localhost' PASSWORD EXPIRE;
Query OK, 0 rows affected (0.04 sec)
在用戶未設(shè)置新密碼之前不能運(yùn)行任何查詢語句,而且會(huì)得到如下錯(cuò)誤消息提示:
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
按照以下操作執(zhí)行完后此用戶的所有操作就又會(huì)被允許執(zhí)行:
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)
重新登錄發(fā)現(xiàn)被拒絕:
[root@localhost ~]# mysql -u mdba -p
Enter password:
ERROR 3118 (HY000): Access denied for user 'mdba'@'localhost'. Account is locked.
解鎖后恢復(fù)正常:
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版開始,用戶的密碼過期時(shí)間這個(gè)特性得以改進(jìn),可以通過一個(gè)全局變量default_password_lifetime來設(shè)置密碼過期的策略,
此全局變量可以設(shè)置一個(gè)全局的自動(dòng)密碼過期策略。
在MySQL5.7的配置文件中設(shè)置一個(gè)默認(rèn)值,這會(huì)使得所有MySQL用戶的密碼過期時(shí)間都為90天,MySQL會(huì)從啟動(dòng)時(shí)開始計(jì)算時(shí)間。
例如在my.cnf里添加:
[mysqld]
default_password_lifetime=90
這會(huì)使得所有MySQL用戶的密碼過期時(shí)間都為90天,MySQL會(huì)從啟動(dòng)時(shí)開始計(jì)算時(shí)間。
如果要設(shè)置密碼永不過期的全局策略,可以設(shè)置default_password_lifetime=0,或者在命令行設(shè)置:
mysql> SET GLOBAL default_password_lifetime = 0;
Query OK, 0 rows affected (0.00 sec)
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“MySQL如何實(shí)現(xiàn)用戶密碼過期功能”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
新聞標(biāo)題:MySQL如何實(shí)現(xiàn)用戶密碼過期功能-創(chuàng)新互聯(lián)
分享URL:http://chinadenli.net/article44/hjdhe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、外貿(mào)建站、做網(wǎng)站、微信小程序、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容