diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 85136e5e09218..35297e8327731 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -38,6 +38,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" + "github.com/pingcap/tidb/util/testutil" ) var _ = Suite(&testIntegrationSuite{}) @@ -390,6 +391,16 @@ func (s *testIntegrationSuite) TestChangingTableCharset(c *C) { c.Assert(tbl.Meta().Columns[0].Collate, Equals, "") tk.MustExec("alter table t convert to charset utf8mb4;") checkCharset() + + tk.MustExec("drop table t") + tk.MustExec("create table t (a blob) character set utf8;") + tk.MustExec("alter table t charset=utf8mb4 collate=utf8mb4_bin;") + tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", + "t CREATE TABLE `t` (\n"+ + " `a` blob DEFAULT NULL\n"+ + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", + )) + } func (s *testIntegrationSuite) TestCaseInsensitiveCharsetAndCollate(c *C) { diff --git a/ddl/table.go b/ddl/table.go index 3a82395316f63..98adb17893217 100644 --- a/ddl/table.go +++ b/ddl/table.go @@ -21,6 +21,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/parser/model" + field_types "github.com/pingcap/parser/types" "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -511,7 +512,7 @@ func onModifyTableCharsetAndCollate(t *meta.Meta, job *model.Job) (ver int64, _ } // update column charset. for _, col := range tblInfo.Columns { - if typesNeedCharset(col.Tp) { + if field_types.HasCharset(&col.FieldType) { col.Charset = toCharset col.Collate = toCollate } else {