前言
實驗:通過 Canal 解析 MySql 的 binlog,擷取sql
一、準備
本實驗在之前配置上進行
采用的 Canal版本,https://github.com/alibaba/canal/issues/574
<dependency>
<groupId>com.alibaba.otter</groupId>
<artifactId>canal.client</artifactId>
<version>1.0.24</version>
</dependency>
二、修改MySql中 binlog_format
檢視binlog_format
show variables like 'binlog_format'
(1)在配置檔案 my.cnf
中更改
my.cnf
(2)直接更改
set globle binlog_format='MIXED'
三、添加代碼
在之前的代碼中添加
String sql = rowChage.getSql();
System.out.println("SQL : " + sql);
四、測試
啟動canal用戶端
./bin/startup.sh
開啟項目應用