maxwell配置使用

官方文档 参考 记录下maxwell的用法:

准备

修改mysql配置开启binlog

1
vim /etc/my.cnf

1
2
3
4
[mysqld]
server_id=1
log-bin=master
binlog_format=row

给maxwell用户添加权限

1
mysql -h localhost -u root -p

1
2
mysql> GRANT ALL on maxwell.* to 'maxwell'@'%' identified by 'XXXXXX';
mysql> GRANT SELECT, REPLICATION CLIENT, REPLICATION SLAVE on *.* to 'maxwell'@'%';

启动运行

在这里和kafka一起启动 先启动zookeeper:

1
2
cd zookeeper-3.4.10
./bin/zkServer.sh start

1
2
cd kafka_2.11-1.1.0
./bin/kafka-server-start.sh config/server.properties
1
2
3
cd maxwell-1.17.1
bin/maxwell --user='maxwell' --password='XXXXXX' --host='127.0.0.1' \
--producer=kafka --kafka.bootstrap.servers=localhost:9092 --kafka_topic=maxwell

同时启动一个kafka console consumer:

1
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic maxwell --from-beginning

添加数据

1
2
3
mysql> create database test;
mysql> use test;
mysql> create table test(id int, name varchar(10), address verchar(20))
1
mysql> insert into test values(1, 'dkey', 'Shanghai')

从kafka console consumer可以读到json数据:

1
{"database":"test","table":"test","type":"insert","ts":1531214750,"xid":2143,"commit":true,"data":{"id":1,"name":"dkey","address":"Shanghai"}}