使用 MySql 遇到的問題

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.

版本問題,使用自動檢測版本方法

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

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.

. 修改認證

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Your New Password';
FLUSH PRIVILEGES;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章