Java读取MySql的binlog⽇志1. 在l中添加jar包
<dependency>
<groupId>com.github.shyiko</groupId>
<artifactId>mysql-binlog-connector-java</artifactId>
<version>0.20.1</version>
</dependency>
2. 读取指定binlog⽂件⾥的内容
public class Application {
public static void main(String[] args) throws IOException {
File file = new File("E:\\binlog.000005");
EventDeserializer eventDeserializer = new EventDeserializer();mysql下载jar包
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 = adEvent()) != null; ) {
EventData data = Data();
if (data != null && Class().isAssignableFrom(RowsQueryEventData.class)) {
RowsQueryEventData dmlData = (RowsQueryEventData) data;
System.out.Query());
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
reader.close();
}
}
}
拿到结果:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。