.NET(C#) 操作MySQL报错Character set 'utf8mb3' is not supported 解决方法

本文主要介绍.NET(C#) 中,操作使用MySQL数据库报错:System.NotSupportedException: Character set 'utf8mb3' is not supported by .Net Framework.的解决方法。

报错信息:

[21:15:49,107] Server Properties Lookup: Error While Initialization
DOL.Database.DatabaseException: Table DOL.Database.ServerProperty is not registered for Database Connection...
at DOL.Database.ObjectDatabase.SelectAllObjects[TObject]()
at DOL.GS.ServerProperties.Properties.get_AllDomainProperties()
at DOL.GS.ServerProperties.Properties.InitProperties()
at DOL.GS.GameServer.InitComponent(Action componentInitMethod, String text)```
also this error
[21:15:35,991] ExecuteSelectImpl: UnHandled Exception for Select Query "DESCRIBE `Specialization`"
System.NotSupportedException: Character set 'utf8mb3' is not supported by .Net Framework.
at MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version, String charSetName)
at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding()
at MySql.Data.MySqlClient.NativeDriver.GetColumnData(MySqlField field)
at MySql.Data.MySqlClient.NativeDriver.GetColumnsData(MySqlField[] columns)
at MySql.Data.MySqlClient.Driver.GetColumns(Int32 count)
at MySql.Data.MySqlClient.ResultSet.LoadColumns(Int32 numCols)
at MySql.Data.MySqlClient.ResultSet..ctor(Driver d, Int32 statementId, Int32 numCols)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlDataReader.Close()
at MySql.Data.MySqlClient.MySqlCommand.ResetReader()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at DOL.Database.SQLObjectDatabase.ExecuteSelectImpl(String SQLCommand, IEnumerable`1 parameters, Action`1 Reader)```

解决方法:

修改字符集和排序为utf8mb4

修改数据:

ALTER DATABASE
database_name
CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci;

修改表:

ALTER TABLE
table_name
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

修改列:

ALTER TABLE
table_name
CHANGE column_name column_name
VARCHAR(191)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

推荐阅读
cjavapy编程之路首页