java数据库登录显示无监听_mysql-binlog-connector-java无法监听到日志的解决办法 (Trying to restore lost connection to localho...
本地代码public class BinlogServiceTest {public static voidmain(String[] args) throws IOException {BinaryLogClient client = new BinaryLogClient("localhost",3306,"root","123456");client.registerEventListe..
本地代码
public class BinlogServiceTest {
public static void main(String[] args) throws IOException {
BinaryLogClient client = new BinaryLogClient(
"localhost",
3306,
"root",
"123456"
);
client.registerEventListener(event -> {
EventData data = event.getData();
if (data instanceof UpdateRowsEventData){
System.out.println("Update---------------");
System.out.println(data.toString());
}else if (data instanceof WriteRowsEventData){
System.out.println("Write---------------");
System.out.println(data.toString());
}else if (data instanceof DeleteRowsEventData){
System.out.println("Delete---------------");
System.out.println(data.toString());
}
}
);
client.connect();
}
}
运行之后,无报错,但是修改数据库也不能被监听到。
控制台显示
Trying to restore lost connection to localhost:3306
可以看到这里尝试重连了mysql
后续发现在listenForEventPackets方法里,有如下异常
server_id was not set 可以得出错误是因为server_id并没有设置。(坑啊,这里居然没把异常打印出来)
解决:
去到配置文件,添加:
server-id =1
重启mysql
关于修改 配置文件及windows下如何重启mysql可移步https://blog.csdn.net/qq_27037443/article/details/96099628
此时修改mysql数据库,监听成功。
更多推荐
所有评论(0)