支持的字符集 本章节介绍DRDS支持的字符集和字符集设置方法。 支持的字符集 DRDS兼容MySQL 5.7和8.0的utf8和utf8mb4字符集,建表时禁止使用除utf8,utf8mb4之外的字符集。本文介绍utf8和utf8mb4字符集的设置方法。 字符集设置 1. 建表时指定字符集 plaintext create table employee ( employeeid int not null comment '雇员标识', name varchar(100) not null comment '雇员名称', email varchar(30) comment 'email地址', createdate datetime comment '创建时间', areaid int comment '区域标识', primary key (employeeid) ) engineinnodb default charsetutf8; alter table employee comment '雇员表'; 或者 plaintext create table employee ( employeeid int not null comment '雇员标识', name varchar(100) not null comment '雇员名称', email varchar(30) comment 'email地址', createdate datetime comment '创建时间', areaid int comment '区域标识', primary key (employeeid) ) engineinnodb DEFAULT CHARSETutf8mb4 COLLATEutf8mb4bin; 注意 建表时,禁止使用使用除utf8,utf8mb4之外的字符集。 2. 客户端和会话连接的字符集配置 为了确保能够正确存储和显示,我们需要在客户端和会话连接中统一使用utf8,utf8mb4字符集,具体说明如下: 客户端配置: 保证客户端输出的字符串的字符集为utf8,utf8mb4。这可以通过设置客户端的字符集编码来实现,确保输出的数据是以utf8,utf8mb4编码发送到DRDS实例。 会话连接配置: 确保到DRDS实例的会话连接支持utf8,,utf8mb4字符集。以JDBC连接为例,需要使用MySQL Connector/J 5.1.13及以上的版本,并且在连接串中不配置characterEncoding选项。