Skip to content

DDL语句的comment中文出现乱码 #610

@dlnufox

Description

@dlnufox

MySQL中,charset为 utf8mb4,collation为 utf8mb4_general_ci

测试过程中建表语句如下:

CREATE TABLE `xxx` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id,自增',
  `run_time` int(13) NOT NULL DEFAULT '0' COMMENT '运行总时长-秒',
  `init_time` int(13) NOT NULL DEFAULT '0' COMMENT '初始化时长-秒',
  `simulation_time` int(13) NOT NULL DEFAULT '0' COMMENT '模拟计算耗时-秒',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='hadoop处理能力标准监控程序运行时长';

Canal server接收后,得到的SQL语句如下:

create table `xxx` (
`id` int(11) NOT NULL auto_increment COMMENT 'šłĽťĒģidԾƍᙌĘě',
`run_time` int(13) NOT NULL DEFAULT 0 COMMENT 'ŤŅźŤ°ĆśÄĽśó∂ťēŅ-Áßí',
`init_time` int(13) NOT NULL DEFAULT 0 COMMENT 'ŚąĚŚßčŚĆĖśó∂ťēŅ-Áßí', 
`simulation_time` int(13) NOT NULL DEFAULT 0 COMMENT 'ś®°śčüŤģ°ÁģóŤÄóśó∂-Áßí', 
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'ŚąõŚĽļśó∂ťóī',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'śõīśĖįśó∂ťóī',
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'hadoopڧĄÁźÜŤÉĹŚäõś†áŚáÜÁõĎśéßÁ®čŚļŹŤŅźŤ°Ćśó∂ťēŅ';

问题可能的原因,在canal server接收到binlog日志时,会从binlog日志中得到 clientCharset = 45,从而得到 charsetName = MacCentralEurope,再解码得出上述的带中文乱码的SQL

charsetName = CharsetConversion.getJavaCharset(clientCharset);

putEntry(45, "utf8mb4", "utf8mb4_general_ci", "MacCentralEurope");

        // 这两项定义是否正确?
        putEntry(45, "utf8mb4", "utf8mb4_general_ci", "MacCentralEurope");
        putEntry(46, "utf8mb4", "utf8mb4_bin", "MacCentralEurope");

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions