dothetrick / binlogportal

mysql binlog同步工具
129 stars 57 forks source link

中文乱码问题 #1

Closed xwxw159263 closed 3 years ago

xwxw159263 commented 3 years ago

做了编码转换,中文会乱码,但是不知道为什么,并不是全部中文会乱码,一部分中文乱码

dothetrick commented 3 years ago

麻烦贴下乱码字段的mysql字段定义,我测试下

目前使用中暂时没发现这个问题,看下字段和表的编码是否是utf8

xwxw159263 commented 3 years ago

你好,谢谢能看见,数据库定义是UTF-8,在entity取出值后,发现因为编码格式英文为UTF-8,中文格式为GBK,中文转码用new String()也转不了,很奇怪的是他中文的乱码不是全乱,就例如  “车轮迹” 只有“迹”字乱码。

------------------ 原始邮件 ------------------ 发件人: "dothetrick/binlogportal" @.>; 发送时间: 2021年4月30日(星期五) 上午9:37 @.>; @.**@.>; 主题: Re: [dothetrick/binlogportal] 中文乱码问题 (#1)

麻烦贴下乱码字段的mysql字段定义,我测试下

目前使用中暂时没发现这个问题,看下字段和表的编码是否是utf8

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

dothetrick commented 3 years ago

方便的话,贴一下mysql数据表的创建语句和出问题的字段当前的值吧。 我测试一下看看。

xwxw159263 commented 3 years ago

DROP TABLE IF EXISTS gg_param; CREATE TABLE gg_param (   ID varchar(38) CHARACTER SET utf8mb4 NOT NULL,   TYPE varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL,   CODE varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL,   NAME varchar(100) CHARACTER SET utf8mb4 DEFAULT NULL,   REMARK varchar(300) CHARACTER SET utf8mb4 DEFAULT NULL,   PRIMARY KEY (ID) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

INSERT INTO gg_param VALUES ('{00153948-4019-11eb-869b-fa163e0f6009}', 'distress_level', 'L', '轻', '病害严重程度'); INSERT INTO gg_param VALUES ('{001a25a2-4019-11eb-869b-fa163e0f6009}', 'distress_level', 'M', '中', '病害严重程度'); INSERT INTO gg_param VALUES ('{001eb968-4019-11eb-869b-fa163e0f6009}', 'distress_level', 'H', '重', '病害严重程度'); INSERT INTO gg_param VALUES ('{2de676b6-3ddc-11eb-869b-fa163e0f6009}', 'distress_pos', 'M', '车道中', '损坏横向位置'); INSERT INTO gg_param VALUES ('{2debbd19-3ddc-11eb-869b-fa163e0f6009}', 'distress_pos', 'LW', '左轮迹', '损坏横向位置'); INSERT INTO gg_param VALUES ('{2df1ae54-3ddc-11eb-869b-fa163e0f6009}', 'distress_pos', 'RW', '右轮迹', '损坏横向位置');

左轮迹,左轮不乱吗,迹乱码,轻字乱码。

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年5月6日(星期四) 下午2:22 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [dothetrick/binlogportal] 中文乱码问题 (#1)

方便的话,贴一下mysql数据表的创建语句和出问题的字段当前的值吧。 我测试一下看看。

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

dothetrick commented 3 years ago

你好,按提供的表结构测试未发现问题。下面是我打印出的日志。 image

监听器的代码也很简单,直接获取调用Entity中的方法获取json字符串,如下:

@Component
@Slf4j
public class LogEventHandler implements IEventHandler {
    public void process(EventEntity eventEntity) throws BinlogPortalException {
        log.info(eventEntity.getJsonFormatData());
    }
}

正常使用的话,是不需要再自己做编码转换的。可以按这个监听器的实现试试看。

也可能是打印展示的问题,可以在linux系统上打印到文件中看一下。

xwxw159263 commented 3 years ago

好的谢谢您了,麻烦了

------------------ 原始邮件 ------------------ 发件人: "dothetrick/binlogportal" @.>; 发送时间: 2021年5月11日(星期二) 上午10:09 @.>; @.**@.>; 主题: Re: [dothetrick/binlogportal] 中文乱码问题 (#1)

你好,按提供的表结构测试未发现问题。下面是我打印出的日志。

监听器的代码也很简单,直接获取调用Entity中的方法获取json字符串,如下: @Component @Slf4j public class LogEventHandler implements IEventHandler { public void process(EventEntity eventEntity) throws BinlogPortalException { log.info(eventEntity.getJsonFormatData()); } }

正常使用的话,是不需要再自己做编码转换的。可以按这个监听器的实现试试看。

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.