mysql出現(xiàn)ERROR 1819 (HY000)的解決方法
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,出現(xiàn)這個問題怎么辦?不用著急,下面給出答案。
為了加強安全性,MySQL5.7為root用戶隨機生成了一個密碼,在error log中,關于error log的位置,如果安裝的是RPM包,則默認是/var/log/mysqld.log。
一般可通過log_error設置
mysql> select @@log_error; +---------------------+ | @@log_error | +---------------------+ | /var/log/mysqld.log | +---------------------+ 1 row in set (0.00 sec)
可通過# grep "password" /var/log/mysqld.log 命令獲取MySQL的臨時密碼
用該密碼登錄到服務端后,必須馬上修改密碼,不然會報如下錯誤:
mysql> select user(); ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
如果只是修改為一個簡單的密碼,會報以下錯誤:
mysql> ALTER USER USER() IDENTIFIED BY '12345678'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
這個其實與validate_password_policy的值有關。
validate_password_policy有以下取值:

默認是1,即MEDIUM,所以剛開始設置的密碼必須符合長度,且必須含有數(shù)字,小寫或大寫字母,特殊字符。
有時候,只是為了自己測試,不想密碼設置得那么復雜,譬如說,我只想設置root的密碼為123456。
必須修改兩個全局參數(shù):
首先,修改validate_password_policy參數(shù)的值
mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec)
這樣,判斷密碼的標準就基于密碼的長度了。這個由validate_password_length參數(shù)來決定。
mysql> select @@validate_password_length; +----------------------------+ | @@validate_password_length | +----------------------------+ | 8 | +----------------------------+ 1 row in set (0.00 sec)
validate_password_length參數(shù)默認為8,它有最小值的限制,最小值為:
validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
其中,validate_password_number_count指定了密碼中數(shù)據(jù)的長度,validate_password_special_char_count指定了密碼中特殊字符的長度,validate_password_mixed_case_count指定了密碼中大小字母的長度。
這些參數(shù),默認值均為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將進行動態(tài)修改。
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插件必須已經(jīng)安裝,MySQL5.7是默認安裝的。
那么如何驗證validate_password插件是否安裝呢?可通過查看以下參數(shù),如果沒有安裝,則輸出將為空。
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)
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Mysql清空表數(shù)據(jù)庫命令truncate和delete詳解
這篇文章主要介紹了Mysql數(shù)據(jù)庫清空表truncate和delete的相關知識,本文給大家講解的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-06-06
MySQL深分頁,limit 100000,10優(yōu)化方式
MySQL中深分頁查詢因需掃描大量數(shù)據(jù)行導致效率低下,優(yōu)化方法包括子查詢優(yōu)化、延遲關聯(lián)、標簽記錄法和使用between...and...等,通過減少回表次數(shù)和范圍掃描提升查詢性能,覆蓋索引幫助減少搜索次數(shù),提升性能2024-10-10
mysql實現(xiàn)本地keyvalue數(shù)據(jù)庫緩存示例
這篇文章主要介紹了代碼實現(xiàn)本地Key-Value緩存示例,大家參考使用吧2013-12-12
MySQL 將文件導入數(shù)據(jù)庫(load data Statement)
本文主要介紹了MySQL 將文件導入數(shù)據(jù)庫,可以使用load data infile語句將文件中的數(shù)據(jù)加載到數(shù)據(jù)庫中,感興趣的可以了解一下2024-09-09

