diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index 40154a1a6..765aa68fd 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -405,6 +405,7 @@ namespace SqlSugar } sql = sql.Replace("$PrimaryKey", primaryKeyInfo); this.Context.Ado.ExecuteCommand(sql); + SetCharSet(tableName, "utf8mb4"); return true; } public override bool AddRemark(EntityInfo entity) @@ -591,5 +592,15 @@ namespace SqlSugar } #endregion + #region Helper + private void SetCharSet(string tableName, string charset) + { + if (this.Context.CurrentConnectionConfig.ConnectionString.ObjToString().ToLower().Contains(charset)) + { + var name = this.SqlBuilder.GetTranslationTableName(tableName); + this.Context.Ado.ExecuteCommand($"ALTER TABLE {name} CONVERT TO CHARACTER SET utf8mb4;"); + } + } + #endregion } } diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs index 62a5e6d8f..e08cb5532 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs @@ -406,6 +406,7 @@ namespace SqlSugar } sql = sql.Replace("$PrimaryKey", primaryKeyInfo); this.Context.Ado.ExecuteCommand(sql); + SetCharSet(tableName, "utf8mb4"); return true; } public override bool AddRemark(EntityInfo entity) @@ -627,5 +628,16 @@ namespace SqlSugar } #endregion + + #region Helper + private void SetCharSet(string tableName, string charset) + { + if (this.Context.CurrentConnectionConfig.ConnectionString.ObjToString().ToLower().Contains(charset)) + { + var name = this.SqlBuilder.GetTranslationTableName(tableName); + this.Context.Ado.ExecuteCommand($"ALTER TABLE {name} CONVERT TO CHARACTER SET utf8mb4;"); + } + } + #endregion } }