C#連線MySQL8.0資料庫失敗

新哲發表於2024-10-16

環境

.net7 MySQL8.0

報錯提示:

未經處理的異常

System.AggregateException:“One or more errors occurred. (Authentication method 'caching_sha2_password' failed. Either use a secure connection, specify the server's RSA public key with ServerRSAPublicKeyFile, or set AllowPublicKeyRetrieval=True.)”

內部異常

SqlSugarException: Authentication method 'caching_sha2_password' failed. Either use a secure connection, specify the server's RSA public key with ServerRSAPublicKeyFile, or set AllowPublicKeyRetrieval=True.

解決方法:

資料庫連線字元內加:AllowPublicKeyRetrieval=True

原資料庫連線字元:Data Source=192.168.28.9;port=3306;User ID=MySQLName;Password=123456;Database=mdgk_zlfq;CharSet=utf8mb4;sslmode=none;AllowLoadLocalInfile=true;

新增後:Data Source=127.0.0.1;port=3306;User ID=MySQLName;Password=123456;Database=asdf;CharSet=utf8mb4;sslmode=none;AllowLoadLocalInfile=true;AllowPublicKeyRetrieval=True;

相關文章