sql报错非法的字符校对Illegal mix of collations
0.报错sql如下(查询单个表都没问题,关联就会报错):
SELECT
,A.SCH_TYPE
,A.CYCLE
,B.ID ISREPLY
,A.UPDATE_TIME
,A.DESCR
,A.CATEGORY_ID
,D.PARAM_NAME as fLOW_TYPE
FROM DMGR_FLOW A
LEFT JOIN DMGR_PARAM D ON A.FLOW_TYPE = D.PARAM_VALUE
;
Illegal mix of collations
1.查看建表语句,发现字符集不一样
一个是:CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
另一个是:CHARSET = utf8mb4
CREATE TABLE dmgr_flow
(
ID
decimal(18,0) NOT NULL,
NAME
varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '作业流名称',
CRON_EXPRESSION
varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '执行时间',
SCH_TYPE
varchar(2) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '调度类型',
CYCLE
varchar(2) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '调度周期',
OWNER
decimal(18,0) DEFAULT NULL COMMENT '创建人',
CATEGORY_ID
decimal(18,0) DEFAULT NULL COMMENT '分类id',
DESCR
varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '描述',
ACTIVE_TIME
datetime DEFAULT NULL COMMENT '生效时间',
INACTIVE_TIME
datetime DEFAULT NULL COMMENT '失效时间',
CREATE_TIME
datetime NOT NULL COMMENT '创建时间',
UPDATE_TIME
datetime NOT NULL COMMENT '更新时间',
FLOW_TYPE
varchar(12) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '作业流类型',
STATUS
varchar(2) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '状态',
CLAIM_ID
decimal(65,0) DEFAULT NULL COMMENT '报警主键',
UPDATE_USER
decimal(18,0) DEFAULT NULL COMMENT '修改人id',
PROJECT_ID
decimal(18,0) DEFAULT NULL COMMENT '项目id',
PRIMARY KEY (ID
),
KEY CATEGORY_FLOW_FK
(CATEGORY_ID
) BLOCK_SIZE 16384 GLOBAL
) DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 3 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 COMMENT = '作业流';
CREATE TABLE dmgr_param
(
id
int(11) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
param_type
char(32) DEFAULT NULL COMMENT '参数类型',
param_name
char(32) DEFAULT NULL COMMENT '参数名称',
param_value
char(32) DEFAULT NULL COMMENT '参数值',
content
char(64) DEFAULT NULL COMMENT '参数内容',
operation_user
char(32) DEFAULT NULL COMMENT '用户',
create_time
datetime DEFAULT NULL,
update_time
datetime DEFAULT NULL,
PRIMARY KEY (id
),
UNIQUE KEY param_type
(param_type
, param_name
) BLOCK_SIZE 16384 GLOBAL
) AUTO_INCREMENT = 1000182 DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 3 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 COMMENT = '参数表';
- 修改表的字符集(有的数据库不支持修改,需要删除表重建)
alter table dmgr_param convert to CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
3.重新执行就不报错了