v4.0.14迁移升级到v6.5.10遇到的字符集问题

Hacker_lBbigVlk
Tue, 03 Sep 2024 07:03:43 +0000

背景：迁移机房，升级版本
源集群：v4.0.14
参数 new_collations_enabled_on_first_bootstrap=true

目标集群：v6.5.10
参数 new_collations_enabled_on_first_bootstrap=true

表结构：
CREATE TABLE im_c (
customer_im_id int(11) NOT NULL AUTO_INCREMENT COMMENT ‘Id’,
dealer_id int(11) DEFAULT NULL COMMENT ‘ID’,
das_account_ids varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘ID’,
im_id int(11) DEFAULT NULL COMMENT ‘IMID’,
customer_name varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘’,
customer_gender int(11) DEFAULT NULL COMMENT ‘’,
customer_nick_name varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘’,
customer_portrait_url varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘’,
customer_friends_state varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘’,
customer_phone_code bigint(20) DEFAULT NULL COMMENT ‘手机号编码’,
customer_phone varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘’,
im_create_time datetime(3) DEFAULT NULL COMMENT ‘会话创建时间’,
last_lead_create_time datetime(3) DEFAULT NULL COMMENT ‘’,
last_msg_time datetime(3) DEFAULT NULL COMMENT ‘’,
is_active smallint(6) DEFAULT ‘1’ COMMENT ‘’,
car_id int(11) DEFAULT NULL COMMENT ‘车款ID’,
order_remark varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘’,
location_id int(11) DEFAULT NULL COMMENT ‘’,
license_location_id int(11) DEFAULT NULL COMMENT ‘’,
info_source_id int(11) DEFAULT ‘0’ COMMENT ‘’,
loan_type smallint(6) DEFAULT NULL COMMENT ‘’,
replacement_type smallint(6) DEFAULT NULL COMMENT ‘’,
buy_potential smallint(6) DEFAULT NULL COMMENT ‘buy_potential’,
dealer_follow_status smallint(6) DEFAULT ‘0’ COMMENT ‘’,
fist_follow_time datetime(3) DEFAULT NULL COMMENT ‘’,
last_follow_time datetime(3) DEFAULT NULL COMMENT ‘’,
create_time datetime(3) DEFAULT CURRENT_TIMESTAMP(3) COMMENT ‘’,
modify_time datetime(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT ‘’,
is_create_card smallint(6) DEFAULT ‘0’ COMMENT ‘’,
customer_card_name varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘’,
customer_card_phone_code bigint(20) DEFAULT NULL COMMENT ‘’,
source varchar(1500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ‘’,
PRIMARY KEY (customer_im_id),
UNIQUE KEY unIdx_IMID_DealerId (im_id,dealer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=19836175 COMMENT=‘IM’

应用程序连接字符串：jdbc:mysql://tidb12344.service.idc:4000/crm?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai

应用程序切换连接到新集群后报错：

Cause: java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation ‘find_in_set’

sql为：update im_c set das_account_ids = CASE WHEN find_in_set( CAST(? as CHAR) ,das_account_ids) > 0 THEN das_account_ids ELSE CONCAT(das_account_ids,CAST(? as CHAR),‘,’) END where customer_im_id in (?);

问题：请问v4版本和v6版本在字符集设置方面有哪些不同？
ps:这个问题我们已经解决了，在session级别设置了一下字符集和排序规则。或者直接在语句中指定字符集或排序规则。我主要的问题是：两个版本之间有什么差异

阅读完整话题