一、语法介绍
alter table tbname convert to character set utf8mb4;
alter table tbname convert to charset utf8mb4;
二、使用说明
原表中的char、varchar类型字符集转为utf8mb4
新增列中char,varchar,text,lonegtext类型字符集为utf8mb4
原表字符集为utf8/utf8mb4,目标字符集为utf8mb4
不支持修改列字符集,执行成功但不生效
三、示例:
gbase>create table t(i int,c char(20),v varchar(100),t text,b blob) charset utf8;
Query OK,0 rows affected(Elapsed:00:00:00.54)
gbase>alter table t convert to charset utf8mb4;
Query OK,0 rows affected(Elapsed:00:00:01.03)
gbase>show create table t;
+--------+---------------------------------------------------------------------------------------------------------+
| Table | Create Table |
| t | CREATE TABLE "T"(
"i" int(11) DEFAULT NULL,
"c" char(20) DEFAULT NULL,
"v" varchar(100) DEFAULT NULL,
"t" text CHARACTER SET utf8,
"b" blob
) ENGINE=EXPRESS DEFAULT CHARSET=utf8mb4 TABLESPACE='sys_tablespace' |
+-------+----------------------------------------------------------------------------------------------------------+
1 rows in set(Elapsed:00:00:00.01)
gbase>alter table t convert to charset utf8mb4;
Query OK,0 rows affected(Elapsed:00:00:00.86)
gbase>alter table t add (c2 char(50),v2 varchar(50),t2 text,b2 blob);
Query OK,0 rows affected(Elapsed:00:00:00.89)
Records:0 Duplicates:0 Warnings:0
gbase>show create table t;
+--------+---------------------------------------------------------------------------------------------------------+
| Table | Create Table |
| t | CREATE TABLE "T"(
"i" int(11) DEFAULT NULL,
"c" char(20) DEFAULT NULL,
"v" varchar(100) DEFAULT NULL,
"t" text CHARACTER SET utf8,
"b" blob,
"c2" char(50) DEFAULT NULL,
"v2" varchar(50) DEFAULT NULL,
"t2" text,
"b2" blob,
) ENGINE=EXPRESS DEFAULT CHARSET=utf8mb4 TABLESPACE='sys_tablespace' |
+-------+----------------------------------------------------------------------------------------------------------+
1 rows in set(Elapsed:00:00:00.00)