java - mysql binlog reader from remote server

1. Configure your server to enable binlog in my.cnf file. The bold configurations are required.

## enable binlog
server_id=1
log_bin = /path/to/your/binlogfile.log
expire_logs_days = 10
max_binlog_size = 100M
binlog-format = row

2. Grant REPLICATION SLAVE, REPLICATION CLIENT privileges to user to read binlog from remote server
Login mysql with root user, then run command below:

GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'binloguser'@'%' IDENTIFIED BY '123456a@';

3. Test binlog reading from a remote server 

mysqlbinlog -R -h192.168.146.252 --port=3307 -ubinloguser -p mysql-bin.000001

Note: 
-R option instructs mysqlbinlog command to read the log file from the remote server
-h specify the ip-address of the remote server
-p This will prompt you for the password. 
mysqld-bin.000001 This is the name of the binary log file from the remote server that we are reading here

4. Read binlog with Java 
https://github.com/shyiko/mysql-binlog-connector-java

No comments:

Post a Comment