- 在pom.xml中添加jar包
<dependency>
<groupId>com.github.shyiko</groupId>
<artifactId>mysql-binlog-connector-java</artifactId>
<version>0.20.1</version>
</dependency>
- 读取指定binlog文件里的内容
public class Application {
public static void main(String[] args) throws IOException {
File file = new File("E:\\binlog.000005");
EventDeserializer eventDeserializer = new EventDeserializer();
eventDeserializer.setCompatibilityMode(
EventDeserializer.CompatibilityMode.DATE_AND_TIME_AS_LONG,
EventDeserializer.CompatibilityMode.CHAR_AND_BINARY_AS_BYTE_ARRAY
);
BinaryLogFileReader reader = new BinaryLogFileReader(file, eventDeserializer);
try {
for (Event event; (event = reader.readEvent()) != null; ) {
EventData data