ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

爲了增強安全性,MySQL5.7爲root用戶隨機生成了一個密碼,在error log中,關於error log的位置,若是安裝的是RPM包,則默認是/var/log/mysqld.log。mysql

通常可經過log_error設置sql

mysql> select @@log_error;
+---------------------+
| @@log_error         |
+---------------------+
| /var/log/mysqld.log |
+---------------------+
1 row in set (0.00 sec)

可經過# grep "password" /var/log/mysqld.log 命令獲取MySQL的臨時密碼安全

2016-01-19T05:16:36.218234Z 1 [Note] A temporary password is generated for root@localhost: waQ,qR%be2(5

用該密碼登陸到服務端後,必須立刻修改密碼,否則會報以下錯誤:測試

mysql> select user();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

若是隻是修改成一個簡單的密碼,會報如下錯誤:ui

mysql>  ALTER USER USER() IDENTIFIED BY '12345678';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

這個其實與validate_password_policy的值有關。this

validate_password_policy有如下取值:spa

Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file

默認是1,即MEDIUM,因此剛開始設置的密碼必須符合長度,且必須含有數字,小寫或大寫字母,特殊字符。插件

有時候,只是爲了本身測試,不想密碼設置得那麼複雜,譬如說,我只想設置root的密碼爲123456。code

必須修改兩個全局參數:orm

首先,修改validate_password_policy參數的值

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

這樣,判斷密碼的標準就基於密碼的長度了。這個由validate_password_length參數來決定。

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          8 |
+----------------------------+
1 row in set (0.00 sec)

validate_password_length參數默認爲8,它有最小值的限制,最小值爲:

validate_password_number_count
+ validate_password_special_char_count
+ (2 * validate_password_mixed_case_count)

其中,validate_password_number_count指定了密碼中數據的長度,validate_password_special_char_count指定了密碼中特殊字符的長度,validate_password_mixed_case_count指定了密碼中大小字母的長度。

這些參數,默認值均爲1,因此validate_password_length最小值爲4,若是你顯性指定validate_password_length的值小於4,儘管不會報錯,但validate_password_length的值將設爲4。以下所示:

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          8 |
+----------------------------+
1 row in set (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          4 |
+----------------------------+
1 row in set (0.00 sec)

若是修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一個值,則validate_password_length將進行動態修改。

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          4 |
+----------------------------+
1 row in set (0.00 sec)

mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
|                                    1 |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> set global validate_password_mixed_case_count=2;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
|                                    2 |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          6 |
+----------------------------+
1 row in set (0.00 sec)

固然,前提是validate_password插件必須已經安裝,MySQL5.7是默認安裝的。

那麼如何驗證validate_password插件是否安裝呢?可經過查看如下參數,若是沒有安裝,則輸出將爲空。

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_dictionary_file    |       |
| validate_password_length             | 6     |
| validate_password_mixed_case_count   | 2     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
6 rows in set (0.00 sec)
相關文章
相關標籤/搜索