由于新的作業系統沒有安裝mysql,專案中需要使用到,于是安裝了最新版本的mysql8.0.28(我安裝的是社區版),如果你的專案是老專案,使用的mysql插件是比較老的版本,安裝的時候要注意一下,配置mysql的時候會有如下圖的提示,如果是比較老的版本請選擇下面的選項,否則使用第一個選項的話有可能會導致專案連接不上資料庫
安裝完成后,運行專案發現連接不上資料庫,提示如下錯誤資訊
System.Security.Authentication.AuthenticationException: 呼叫 SSPI 失敗,請參見內部例外, ---> System.ComponentModel.Win32Exception: 接收到的訊息例外,或格式不正確,
--- 內部例外堆疊跟蹤的結尾 ---
在 System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
在 MySql.Data.MySqlClient.NativeDriver.StartSSL()
在 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()
在 Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader)
在 Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command)
在 Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType)
百度查詢了一下,說是要升級專案中的mysql插件,我嘗試升級Mysql插件,但是升級失敗了,所有這個解決方案pass掉了,大家可以嘗試一下參考檔案:https://blog.csdn.net/wqq1027/article/details/119764268
于是我就繼續問了度娘,有人說連接字符中中加上SslMode=None;于是我嘗試了一下,還是連接失敗,但是報錯資訊不一樣了,錯誤資訊如下:
Authentication to host 'xxx' for user 'root' using method 'caching_sha2_password' failed with message
看到這個錯誤,我就猜想應該是mysql 8.0密碼驗證機制問題導致,之前在其他文章上面看到過修改方法,修改一下my.ini檔案如下:
如果安裝目錄下找不到my.ini檔案 windows系統下處理如下,打開C盤 查看選項中,查看隱藏檔案,如果不出意外在programeData下(C:\ProgramData\MySQL\MySQL Server 8.0)找到my.ini
加入這一項 default_authentication_plugin=mysql_native_password
[mysqld] default_authentication_plugin=mysql_native_password
然后在服務中重啟MySql服務
Linux 下可以修改在/etc/my.cnf檔案
重啟MySql服務后,再重試發現資料庫連接成功了,記錄一下,以免后面再遇到這種問題,到處找解決方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/423680.html
標籤:其他
