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

在redhat7上安裝mysql時,使用臨時密碼登錄後,修改密碼時,報以下錯誤:

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

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

可以使用命令查找出該隨機密碼:

grep 'temporary password'  /var/log/mysqld.log

緊接下來需要使用臨時密碼登錄進去mysql

登錄進去之後,接下來要做的是修改密碼:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密碼';

會報錯:

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

原因分析:
這個其實與validate_password.policy的值有關。

validate_password.policy有以下取值:

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

強度爲LOW:代表密碼任意,但長度在8位或以上。

強度爲MEDIUM:代表密碼包括:數字、大寫字母、小寫字母、特殊符號、長度8位以上。

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

解決方案如下:
step1: 更改策略,設置 validate_password.policy=0;

mysql>set global validate_password.policy=0;

step2:重設密碼:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密碼';
Query OK, 0 rows affected, 1 warning (0.00 sec)

注意:如果密碼設置爲 123456,會報錯,因爲密碼長度不夠,上述3中策略都要求密碼長度至少是8位。向設置密碼爲123456該怎麼做?放文末再介紹。

step3: 授予root用戶遠程訪問權限:

mysql> grant all privileges on *.* to 'root' @'%' identified by '你的密碼';

step4: 刷新權限,使設置生效, OK。

mysql> flush privileges;

這4步對應的代碼如下:

注意:
默認密碼長度是8;所以少於8位會報錯。

怎麼查看密碼長度:

mysql> select @@validate_password_length;

怎麼修改密碼長度:

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

不管設置 validate_password_length=1,還是2,3,4 ,‘使密碼長度生效’這個參數的實際值都是4。超過4後設置是多少實際就是多少。

額外擴展:

validate_password_length參數默認爲8,它有最小值的限制,最小值是4。這也就是爲什麼設置爲1,或2,3,4時是4。

最小值公式:

其中,

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。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章