關于 mysql5 改密碼后不能登錄的問題
felixsun
2004-04-19
首先說明一下,下面描述僅限于win系統 其它系統我沒試過,
mysql 自從4.1.1以后修改了用戶密碼的格式, 從16位增加到了41位, 采用了一種新的驗證方法,
但4.1以前的客戶端協議不支持這種方法,所以造成了不能登臨的后果.
即使密碼正確了不能正常登錄,提示如下
#1250 - client does not support authentication protocol requested by server; consider upgrading mysql client
在窗口中執行:
c:/mysql/bin>mysql -uroot
welcome to the mysql monitor. commands end with ; or /g.
your mysql connection id is 1 to server version: 5.0.0-alpha-nt
type 'help;' or '/h' for help. type '/c' to clear the buffer.
mysql> select password('aa');
+-------------------------------------------+
| password('aa') |
+-------------------------------------------+
| *dee59c300700af9b586f9f2a702231c0ac373a13 |
+-------------------------------------------+
1 row in set (0.00 sec)
mysql>
從上可以看出password的結果返回了一個以'*'號開頭的41位字符串,而以前是16位的
mysql官方網站給出了二種解決方法
1,使用新的客戶端api,
2,強制服務器使用舊的密碼方案
我首先嘗試了第一種方法,從mysql5.0中拷貝libmysql.dll到php 的擴展目錄中,替代了php本身附帶的libmysql.dll, 但結果令人失望. php提示裝入php_mysql.dll失敗:
php warning: php startup: unable to load dynamic library 'c:/php5/ext/php_mysql.dll' - 找不到指定的程序。
后來發現新版的dll中缺少了mysql_drop_db() 這一函數 :( 只有等php或mysql出更新的dll了.
第一種方法行不通,只有試試第二種方法,mysql的官方faq中說,需要加上-old-password這一參數,
我首先嘗試 在命令行下起動mysql,
c:/mysql/bin>mysqld-nt -old-password
在另一窗口中 運行
c:/mysql/bin>mysql -uroot
welcome to the mysql monitor. commands end with ; or /g.
your mysql connection id is 540 to server version: 5.0.0-alpha-nt
type 'help;' or '/h' for help. type '/c' to clear the buffer.
mysql> select password('mypassword');
+------------------------+
| password('mypassword') |
+------------------------+
| 162eebfb6477e5d3 |
+------------------------+
1 row in set (0.55 sec)
mysql>
可以看出password的結果又變成16位的了,可喜的變化, ,
[省略彎路若干..........]
我在c:/windows/my.ini (xp,98,中如此,2000中應在c:/wint/下)中的"mysqld"段中加入"set-variable=old-passwords"
例:
[mysqld]
basedir=c:/mysql
set-variable=old-passwords
datadir=c:/mysql/data
[winmysqladmin]
server=c:/mysql/bin/mysqld-nt.exe
user=root
password=mypassword
然后在服務管理器中起動mysql
very good, 一切正常,
后來我又發現,只要在mysql.user表中把password的字段長度改成16系統就自動切換到了oldpassword方式,改成改回41后 又自動換到了新的驗證方式.
在這里提醒一下,更改password方式后,要重新設制一下密碼并刷新一下權限(或重起mysql)
菜鳥學堂: