mysql 5.6.25報錯ERROR 1372 (HY000): Password hash 的一點思考
問題背景:
之前使用的一套mysql 5.6.25,由於一些原因我進行了清除。大家知道我們第二次執行mysql_install_db初始化資料庫時,是不會儲存root的臨時密碼。
那麼要進入mysql資料庫,就引入如下的一篇文章。
案例過程:
0,以無密碼認證方式啟動資料庫
[root@standbygtid mysql]#nohup mysqld_safe --user=mysql --skip-grant-tables&
1,配置root使用者的密碼
mysql> set password for 'root'@'localhost'='system';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
2,重新整理修改使用者密碼的操作到mysql.user表
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
3,修改資料庫使用者密碼,提示密碼需要41個位元組
mysql> set password for 'root'@'localhost'='system';
ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number
4,採用password函式修改使用者密碼成功
mysql> set password for 'root'@'localhost'=password('system');
Query OK, 0 rows affected (0.00 sec)
5,關閉資料庫
[root@standbygtid mysql]#mysqladmin -uroot -psystem shutdown
6,啟動資料庫
[root@standbygtid mysql]# nohup mysqld_safe --user=mysql&
7,可以用上述配置的資料庫使用者密碼登陸
[root@standbygtid mysql]# mysql -uroot -psystem
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2015, 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>
8,password函式不管採用的字串是多少位,產生的位元組寬度全是 41
mysql> select password('system'),length(password('system'));
+-------------------------------------------+----------------------------+
| password('system') | length(password('system')) |
+-------------------------------------------+----------------------------+
| *576EE5B74C20E68F2A5A240F3E408E6DE43DD73F | 41 |
+-------------------------------------------+----------------------------+
1 row in set (0.00 sec)
mysql> select password('syste'),length(password('syste'));
+-------------------------------------------+---------------------------+
| password('syste') | length(password('syste')) |
+-------------------------------------------+---------------------------+
| *795AF4045357E7DA27CBF22263514F881880C4AC | 41 |
+-------------------------------------------+---------------------------+
1 row in set (0.00 sec)
9,上述 41位元組到底是什麼含義呢,查閱mysql 5.6官方文件,上述這個41個位元組是和採用密碼認證的方法有關係,而
採用密碼認證的方法是由系統變數old_passwords控制。
10,old_passwords系統變數的含義
old_passwords控制password函式所使用的密碼認證方法,它會影響create user以及grant操作如何產生資料庫使用者密碼。
old_passwords的幾個值
值 密碼雜湊方法 密碼雜湊方法採用的外掛 是否預設值
0 mysql 4.1版本採用的雜湊方法 mysql_native_password 是
1 mysql 4.1之前的雜湊方法 sha256_password
2 sha-256雜湊方法 sha256_password
11,可見不同的old_password的值,會影響password函式產生的值的寬度
mysql> set old_passwords=0;
Query OK, 0 rows affected (0.00 sec)
mysql> select password('syste'),length(password('syste'));
+-------------------------------------------+---------------------------+
| password('syste') | length(password('syste')) |
+-------------------------------------------+---------------------------+
| *795AF4045357E7DA27CBF22263514F881880C4AC | 41 |
+-------------------------------------------+---------------------------+
1 row in set (0.00 sec)
mysql> set old_passwords=1;
Query OK, 0 rows affected (0.00 sec)
mysql> select password('syste'),length(password('syste'));
+-------------------+---------------------------+
| password('syste') | length(password('syste')) |
+-------------------+---------------------------+
| 46acda267e174d58 | 16 |
+-------------------+---------------------------+
1 row in set (0.00 sec)
mysql> set old_passwords=2;
Query OK, 0 rows affected (0.00 sec)
mysql> select password('syste'),length(password('syste'));
+----------------------------------------------------------------------+---------------------------+
| password('syste') | length(password('syste')) |
+----------------------------------------------------------------------+---------------------------+
| $5$\]^D8P`aMt\vp2Pu$lDCzMsToPBl56CdhB2pjetpvqEiL9BMhdt1TDbMbzL6 | 68 |
+----------------------------------------------------------------------+---------------------------+
1 row in set (0.01 sec)
12,上述old_passwords的不同值是對應於下述不同的外掛
mysql> show plugins;
+----------------------------+----------+--------------------+---------+-------------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+---------+-------------+
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | PROPRIETARY |
| mysql_old_password | ACTIVE | AUTHENTICATION | NULL | PROPRIETARY |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | PROPRIETARY |
13,如果你想指定資料庫在啟動或建立時的預設的使用者密碼認證外掛
這個外掛是對應上述show plugins的值,而沒有對應的系統變數,只有選項,見下
--default-authentication-plugin
可選值:
mysql_native_password 預設值
sha256_password
可以在啟動資料庫時在命令列上指定或者在配置檔案中指定這個選項
14,如果在升級mysql時,一定要好好考量old_password的值或者--default-authentication-plugin,否則舊版本的mysql
客戶端可能會登陸不上升級後的mysql資料庫。
思考總結:
-
1,出現問題,根據錯誤提示進行字面意思分析
-
2,出現問題,在官方手冊查詢對應出錯語句的語法,可以獲取進一步的診斷資訊或線索
-
3,提出的問題,一定要放在一個大的背景下,就是要向業務服務,你的業務的目標是什麼,比如:資料庫使用者的可靠性及安全性,資料庫馬上要升級嗎,資料庫的效能,等等。
-
4,資料庫的學習是一個迭代式的過程,有些知識,不是一下子可以全面瞭解的,需要從字面或其它的技術反向進行進一步的掌握
大家可以關注我的微信公眾號,每天會定期傳送一些資料庫相關的文章,歡迎交流。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-2662388/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql執行sql指令碼報錯ERROR 1366 (HY000) 解決MySql指令碼Error
- MySQL報錯ERROR 2013 (HY000): Lost connection to MySQL server during queryMySqlErrorServer
- MySQL5.6:mysql_secure_installation 報錯ERROR 2002 (HY000)MySqlError
- 【MySQL】ERROR 1290 (HY000): --secure-file-priv--匯出報錯MySqlError
- MySQL 報錯 ERROR 1290 (HY000): running with the --secure-file-privMySqlError
- mysql錯誤詳解(1819):ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsMySqlErrorUIREM
- MySQL報錯'ERROR 2002 (HY000): Can't connect to local MySQL server through'MySqlErrorServer
- MySQL建立使用者報錯 ERROR 1396 (HY000): Operation CREATE USER failed for 'afei'@'%'MySqlErrorAI
- MySQL 5.7 建立使用者報錯 ERROR 1805 (HY000): Column count of mysql.user is wrongMySqlError
- Mysql連線錯誤ERROR 2003 (HY000)MySqlError
- MYSQL SOURCE報錯 ERROR: ASCIIMySqlErrorASCII
- Percona MySQL 5.6 語句加鎖報錯"ERROR 1665 (HY000): Cannot execute statement"MySqlError
- mysql 8 報錯 ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repositoryMySqlErrorAIStruct
- mysql報錯ERROR 1093MySqlError
- super許可權報錯:ERROR1221(HY000):IncorrectusageofDBGRANTandGLOBALPRIVILEGESError
- MySQL報錯 Error_code: 1045MySqlError
- MySQL5.7叢集(MGR)啟動報ERROR 3092 (HY000)MySqlError
- 阿里雲mysql遠端登入報ERROR 2027(HY000)阿里MySqlError
- MYSQL ERROR 2003 (HY000) CanMySqlError
- 報錯”ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)”Errorlocalhost
- MySQL "ERROR 1010(HY000):Error dropping database(canMySqlErrorDatabase
- 錯誤處理的一點思考 (轉)
- ERROR 1290 (HY000): The MySQL server is running withErrorMySqlServer
- ERROR 1010 (HY000) mysql 5.5.19ErrorMySql
- password_hash加密例項加密
- Centos7-mysql執行報錯ERROR1820(HY000):YoumustresetyourpasswordusingALTERUSERstatementbeforeexecutingthisstatement.CentOSMySqlError
- 【MySQL】ERROR 1878 (HY000): Temporary file write failure.MySqlErrorAI
- vue專案中連線MySQL時,報錯ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password:YES)VueMySqlErrorlocalhost
- MySQL 5.7向表匯入資料包錯"ERROR 13 (HY000): Can't get stat of"MySqlError
- MySQL 5.6修復從庫複製時報錯'ERROR 1872 (HY000): Slave failed to initialize'MySqlErrorAI
- linux下連線mysql報錯ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysqLinuxMySqlErrorServer
- 記一次 打包報錯:Keystore was tampered with, or password was incorrect
- mysql 報錯:ERROR 1366 (HY000): Incorrect string value: ‘\xD5\xC5\xC8\xFD‘ for column ‘name‘ at row 1MySqlError
- nagios監控windows 報NSClient - ERROR: Invalid passwordiOSWindowsclientError
- ubuntu更新報錯Hash Sum mismatchUbuntu
- Mysql報錯Fatal error:Can't open and lock privilege tablesMySqlError
- 【Mysql】ERROR 1872 (HY000): Slave failed to initialize relay log infoMySqlErrorAI
- 關於Support for password authentication 報錯的解決方案