Unsupported modify column charset utf8mb4 not match origin utf8

  • Before upgrading, the following operations are executed in v2.1.0 and earlier versions.

    create table t(a varchar(10)) charset=utf8;
    
    Query OK, 0 rows affected
    Time: 0.106s
    
    show create table t;
    
    +-------+-------------------------------------------------------+
    | Table | Create Table                                          |
    +-------+-------------------------------------------------------+
    | t     | CREATE TABLE `t` (                                    |
    |       |   `a` varchar(10) DEFAULT NULL                        |
    |       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
    +-------+-------------------------------------------------------+
    1 row in set
    Time: 0.006s
    
  • After upgrading, the following error is reported in v2.1.1 and v2.1.2 but there is no such error in v2.1.3 and the later versions.

    alter table t change column a a varchar(20);
    
    ERROR 1105 (HY000): unsupported modify column charset utf8mb4 not match origin utf8
    

Solution:

You can explicitly specify the column charset as the same with the original charset.

alter table t change column a a varchar(22) character set utf8;
  • According to Point #1, if you do not specify the column charset, UTF8MB4 is used by default, so you need to specify the column charset to make it consistent with the original one.

  • According to Point #2, you can obtain the metadata of the table through the HTTP API, and find the column charset by searching the column name and the keyword “Charset”.

    curl "http://$IP:10080/schema/test/t" | python -m json.tool
    

    A python tool is used here to format JSON, which is not required and only for the convenience to add the comments.

    {
        "ShardRowIDBits": 0,
        "auto_inc_id": 0,
        "charset": "utf8",   # The charset of the table.
        "collate": "",
        "cols": [            # The relevant information about the columns.
            {
                ...
                "id": 1,
                "name": {
                    "L": "a",
                    "O": "a"   # The column name.
                },
                "offset": 0,
                "origin_default": null,
                "state": 5,
                "type": {
                    "Charset": "utf8",   # The charset of column a.
                    "Collate": "utf8_bin",
                    "Decimal": 0,
                    "Elems": null,
                    "Flag": 0,
                    "Flen": 10,
                    "Tp": 15
                }
            }
        ],
        ...
    }