1. 程式人生 > 實用技巧 >Connection open error . Authentication to host xxx' for user 'aa' using method 'mysql_native_password' failed with message: Access denied for user 'aaa' (using password:

Connection open error . Authentication to host xxx' for user 'aa' using method 'mysql_native_password' failed with message: Access denied for user 'aaa' (using password:

一,在netcore中,我們使用容器講上下文保持全域性唯一的時候,非同步大併發查mysql,就會導致報以上的異常,這個是什麼原因導致的呢?

二,我們去除錯下,在資料庫連線執行Open前,我們是有pwd這個屬性的

在我們執行open後發現,連線的pwd屬性去掉了

三,由上所得,由於注入容器一樣,然而配置的pwd沒了,再次用這個連線字串去open,就會報錯沒有密碼的錯using password: NO

四,這個時候有怎麼辦呢?如下配置

"ConString": "Server=xxx;Port=61010;Database=xx;Uid=xx;Pwd=xxx;CharSet=utf8mb4;;Persist Security Info=True;
",

在配置新增Persist Security Info=True;這個屬性

四,這個是什麼意思呢?

1》將Persist Security Info設定為true或yes將允許在開啟連線後從連接獲取安全敏感資訊,包括使用者標識和密碼。
2》如果您在建立連線時提供了使用者標識和密碼,那麼當這些資訊被用於開啟連線並被丟棄時,您將得到最大程度的保護。
3》有助於提供更高安全性的選項是將Persist security Info設定為false。

所以加上這個後,使用者密碼會一直保持在連線上,而並不是執行open方法後密碼就不存在了