背景
接手别人项目进行维护,使用Mysql 8.0
数据库正确还原,但是项目却无法启动,经过调试发现以下问题。
MySqlException Authentication method ‘caching_sha2_password’ not supported by any of the available plugins。
![.NET 使用MySql 8.0报caching_sha2_password错误的问题处理-第0张图片](https://www.mlplus.net/wp-content/uploads/2020/10/20200924171901.png)
通常的报这个错误是因为它的身份验证方式是 mysql_native_password
,不是caching_sha2_password
导致。
Mysql 官方相关资料:https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html
解决方法
首先找到MySql 8.0
的安装目录,看一下是否存在my.ini
配置文件,默认安装路径如下:
C:\Program Files\MySQL\MySQL Server 8.0
![.NET 使用MySql 8.0报caching_sha2_password错误的问题处理-第1张图片](https://www.mlplus.net/wp-content/uploads/2020/10/20200924173808.png)
现在并没有发现my.ini
配置文件,经过了解Mysql 8.0
安装后会将配置相关内容保存在以下目录中:
C:\ProgramData\MySQL\MySQL Server 8.0
![.NET 使用MySql 8.0报caching_sha2_password错误的问题处理-第2张图片](https://www.mlplus.net/wp-content/uploads/2020/10/20200924173728-1024x273.png)
打开my.ini
配置文件并找到caching_sha2_password
所在的行。
![.NET 使用MySql 8.0报caching_sha2_password错误的问题处理-第3张图片](https://www.mlplus.net/wp-content/uploads/2020/10/20200924173902-1024x644.png)
将default_authentication_plugin=caching_sha2_password
替换为default_authentication_plugin=mysql_native_password
![.NET 使用MySql 8.0报caching_sha2_password错误的问题处理-第4张图片](https://www.mlplus.net/wp-content/uploads/2020/10/20201005173902.png)
操作完成后保存,然后重启mysql 8.0
服务即可。