MySql.Data.dll 因版本问题造成报错的处理

NetCore 链接MySQL 报 Character set ‘utf8mb3‘ is not supported by .Net Framework 异常解决_character set utf8mb3_csdn_aspnet的博客-CSDN博客

查看mysql版本号,两种办法:

第一种在数据库中执行查询:SELECT @@version;

MySql.Data.dll 因版本问题造成报错的处理_第1张图片

第二种使用工具 Navicat:

点击连接节点:

 

在右侧会显示mysql版本:

MySql.Data.dll 因版本问题造成报错的处理_第2张图片

使用8.0.1x的MySql.Data.dll连接mysql8.0.xx版本mysql数据库,连接数据库时会报错:Authentication method 'caching_sha2_password' not supported by any of the available plugins. 

印象中(具体版本记不清了)MySQL数据库版本大于8.0.26使用8.0.1x的MySql.Data.dll就会报上面的异常信息,MySql.Data.dll版本信息如下:

MySql.Data.dll 因版本问题造成报错的处理_第3张图片

解决方式:(两种),第一种需要重启mysql服务,第二种不需要重启服务

第一种:

mysql文件中增加my.ini文件,内容如下,关键时最后一行:default_authentication_plugin=mysql_native_password

MySql.Data.dll 因版本问题造成报错的处理_第4张图片

然后修改mysql的配置文件路径:

打开cmd,进入命令行,输入:mysqld --defaults-file="D:\soft\mysql-8.0.23-winx64\my.ini"

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_bin
init_connect='SET NAMES utf8mb4'
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = D:\\soft\mysql-8.0.23-winx64
datadir = D:\\soft\mysql-8.0.23-winx64\data
port = 3306
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 16M
read_rnd_buffer_size = 16M 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default_authentication_plugin=mysql_native_password

其实相当于降低数据库版本,本机安装了mysql8.0.32版本设置了default_authentication_plugin:

 

然后重启mysql服务:

net stop mysql

net start mysql

但是重启之后还是不能连接:

第二种

更换高版本的MySql.Data.dll文件,由于项目时nuget安装包,所以再项目发布后,将MySql.Data.dll替换为高版本程序可正常运行,其实是将发布后的8.0.15版本的MySql.Data.dll替换为8.0.29版本的MySql.Data.dll,如下:

MySql.Data.dll 因版本问题造成报错的处理_第5张图片

 替换后访问程序均正常,后续可能将使用MySqlConnector.dll,尽量避免此问题。

 

 

 

你可能感兴趣的:(Mysql,windows,.Net,Core,mysql,windows,netcore)