当前位置:   article > 正文

使用 MySql 遇到的问题_system.invalidoperationexception: an exception has

system.invalidoperationexception: an exception has been raised that is likel

1. Entity Framework Core 连接 MySql

连接数据库出现以下错误:

System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseMySql' call.

版本问题,使用自动检测版本方法

  1. var connectionString = configuration.GetConnectionString(connectStr);
  2. services.AddDbContext<T>(options =>
  3. {
  4. options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
  5. });

2. 认证问题

MySql 8.0 默认使用 caching_sha2_password 插件认证,解决方法:

. https://mysqlconnector.net/troubleshooting/retrieval-public-key/#:~:text=To%20retrieve%20the%20server%E2%80%99s%20public%20key%2C%20connect%20securely,to%20the%20connection%20string%3B%20this%20is%20potentially%20insecure.

. 修改认证

  1. ALTER USER '用户名'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
  2. FLUSH PRIVILEGES;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/891856
推荐阅读
相关标签
  

闽ICP备14008679号