【筆記】新版php連接舊版mysql密碼錯誤問題

30 8月, 2019

【筆記】新版php連接舊版mysql密碼錯誤問題








舊版mysql連接密碼問題

情境:使用新版的PHP(7.3)連接舊版的MYSQL(5.0)

問題:無法連上,Console 出現下列錯誤

mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD(‘your_existing_password’). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file

問題原因:
密碼長度錯誤,舊版密碼是採用長度16的方式做hash,新版採用長度41,導致解析hash的時候失敗。

解決方式:
在sql的console視窗輸入以下指令,將長度16的密碼更改為41的長度。

//查詢目前所有密碼長度
SELECT user, Length(Password) FROM mysql.user;
//按照之前的版本設定密碼
SET SESSION old_passwords = FALSE;
//重新更新密碼
UPDATE mysql.user SET Password = PASSWORD('{YOUR_PASSWORD}') WHERE user = '{YOUR_USER}';
//強制生效
FLUSH PRIVILEGES ;
view raw 16to41 hosted with ❤ by GitHub



張貼留言