MySQL 設定使用者密碼過期策略

2022-09-14 22:27:29 字數 2592 閱讀 7406

1.在mysql執行時可以使用超級許可權修改此配置:

mysql> set global default_password_lifetime = 90;

query ok, 0 rows affected (0.00 sec)

還可以使用alter user命令為每個具體的使用者賬戶單獨設定特定的值,它會自動覆蓋密碼過期的全域性策略。要注意alter user語句的interval的單位是「天」。

alter user 『testuser』@『localhost' password expire interval 30 day;

#配置檔案

[mysqld]

default_password_lifetime=90

or#命令列全域性修改

mysql> set global default_password_lifetime = 90;

query ok, 0 rows affected (0.00 sec)

mysql>

mysql> show variables like "default_password_lifetime";

+---------------------------+-------+

| variable_name             | value |

+---------------------------+-------+

| default_password_lifetime | 90    |

+---------------------------+-------+

2.設定單個密碼可重複使用時間和可重複使用的間隔次數

-- 設定密碼為每間隔5次才可以重複使用

mysql> create user yeyz3@'127.0.0.1' identified with 'mysql_native_password' by 'yeyz3' password history 5;

query ok, 0 rows affected (0.01 sec)

-- 設定密碼為每隔5天才可以重複使用

mysql> create user yeyz4@'127.0.0.1' identified with 'mysql_native_password' by 'yeyz4' password reuse interval 5 day;

query ok, 0 rows affected (0.01 sec)

-- 設定密碼為每隔5天可以重複使用或者每個5次才可以重複使用,取最嚴格的那個條件

mysql> create user yeyz5@'127.0.0.1' identified with 'mysql_native_password' by 'yeyz5' password reuse interval 5 day password history 5;

query ok, 0 rows affected (0.01 sec)

-- 使用預設的全域性密碼可重複使用策略,也就是password history引數和password reuse interval引數

mysql> create user yeyz6@'127.0.0.1' identified with 'mysql_native_password' by 'yeyz6' password reuse interval default password history default;

query ok, 0 rows affected (0.01 sec)

3.讓使用者使用預設的密碼過期全域性策略:

alter user  'testuser'@'localhost' password  expire default;

4.全域性設定

mysql> set global default_password_lifetime = 90;

單個使用者設定

為每個具體的使用者賬戶單獨設定特定的值

alter user 『test』@『localhost『 password expire interval 30 day;

禁用密碼過期:

alter user 『test『@『localhost『 password expire never;

讓使用者使用預設的密碼過期全域性策略:

alter user 『test『@『localhost『 password expire default;

設定使用者密碼過期

mysql> alter user 『test『@『localhost『 password expire;

檢視使用者是否過期

select user,host,password_expired,password_last_changed,password_lifetime from user;

password_expired:列舉值,設定使用者密碼是否過期的開關,預設為n。

password_last_changed:記錄密碼最近修改的時間

password_lifetime:設定密碼的有效時間,天數

show create user [email protected]『localhost『;

alter user [email protected]『localhost『 identified by 『password『;

mysql設定使用者密碼過期時間

mysql5.7.4之後 修改my.cnf配置檔案 mysqld default password lifetime 90 密碼90天過期 或是 mysqld default password lifetime 0 密碼永不過期或執行時修改 set global default password l...

mysql密碼策略設定

設定密碼過期策略 mysql資料庫使用者同系統使用者一樣,可以設定密碼過期策略,密碼的過期天數可以在配置檔案裡面設定,也可以通過命令設定,通過命令為每個使用者設定密碼的過期天數則會覆蓋系統配置檔案中的設定。1 配置檔案中設定 選項 default password lifetime 過期天數 如果設...

Linux賬戶密碼過期安全策略設定

主機上普通使用者執行crontab e 時,會報錯,資訊如下 you 使用者名稱 are not allowed to access to crontab because of pam configuration.問題排查思路 一 檢查crond許可權。1 cat etc corn.deny,檔案是...