問題的來龍去脈
下載安裝MySQL Connector/Net 6.6.4,在Visual Studio 2012連接至MySQL時會產生錯誤。MySQL Server Version:5.5.23-55。
MySQL連接範例程式碼,主控台應用程式:
Module Module1 Sub Main() Dim conn As New MySql.Data.MySqlClient.MySqlConnection Dim ConnString As String = "" ConnString = "server=x.x.x.x;" _ & "uid=bruce;" _ & "pwd=***********;" _ & "database=?????????;" Try conn.ConnectionString = ConnString conn.Open() Console.WriteLine("MySql連線成功!") Catch ex As MySql.Data.MySqlClient.MySqlException Console.WriteLine("錯誤編號:" & ex.Number) Console.WriteLine("錯誤訊息:" & ex.ToString()) Finally conn.Close() Console.WriteLine("MySql測試完畢!") End Try Console.ReadLine() End Sub End Module
錯誤編號:0
錯誤訊息:MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication method 'mysql_old_password' not supported by any of the available plugins.
於 MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.GetPlugin(String method, NativeDriver driver, Byte[] authData)
於 MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.HandleAuthChange(MySqlPacket packet)
於 MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
於 MySql.Data.MySqlClient.NativeDriver.Open()
於 MySql.Data.MySqlClient.Driver.Open()
於 MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
於 MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
於 MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
於 MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
於 MySql.Data.MySqlClient.MySqlPool.GetConnection()
於 MySql.Data.MySqlClient.MySqlConnection.Open()
於 mysql_test_01.Module1.Main() 於 C:\Users\Bruce\Documents\Visual Studio 2012\Projects\mysql_test_01\mysql_test_01\Module1.vb: 行 14
如果使用【伺服器總管】【資料連接】方式,當輸入完所有資訊按【測試連接】時,會產生一樣錯誤訊息:
Authentication method 'mysql_old_password' not supported by any of the available plugins.
如果按下【確定】更會使Visual Studio 2012 Crash然後重啟。
問題的發生原因
可參考以下討論串:
- http://stackoverflow.com/questions/13706463/authentication-method-mysql-old-password-not-supported
- http://serverfault.com/questions/385378/mysql-connect-the-server-requested-authentication-method-unknown-to-the-clien
- http://dba.stackexchange.com/questions/33447/connect-error-2054-mysql-old-password-issue-still-not-solved
大意是「MySQL在新版本程式裡移除了舊的密碼認證方式,也就是當初幫你設定帳號密碼的人,使用的是舊密碼設定方式。而比較新的API(Connector/Net,好像是6.6.2之後)預設已經移除這種驗證方式。」
問題解決方法
要解決這個'mysql_old_password'的方式有好幾種,例如,啟用MySQL裡old_passwords方法或改用Windows驗證。不過最正確的方式應該是請系統管理者幫忙使用MySQL新密碼產生方法重新產生密碼。
http://forums.mysql.com/read.php?38,578352,578516#msg-578516
回覆刪除官方回覆。