C#连接MySQL8.0数据库失败

环境

.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;

 

posted @ 2024-10-16 12:49  新哲  阅读(529)  评论(0)    收藏  举报