1、mysql开启bin_log
打开my.ini文件(linux中是my.cnf)
log-bin=mysql-bin
binlog-format=ROW
server_id=1
2、确保mysql可以远程登录
如果不行,则登录mysql执行以下sql
use mysql;
update user set host = '%' where user ='root';
flush privileges;
select host,user from user where user='root';
3、下载go-mysql-transfer生产版本
传送门
4、配置go环境
wget https://dl.google.com/go/go1.17.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.17.linux-amd64.tar.gz
vim /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
source /etc/profile
go version
5、app.yml
addr: 127.0.0.1:3307
user: root
pass: 123456
charset : utf8
slave_id: 1001
flavor: mysql
enable_web_admin: true
web_admin_port: 8060
target: mongodb
mongodb_addrs: 192.168.0.211:27017
rule:
-
schema: water
table: user
column_underscore_to_camel: true
value_encoder: json
mongodb_database: demo
6、运行
go-mysql-transfer.exe
nohup go-mysql-transfer &
配置中开启监控后访问 ip:8060
7、注意
如果mysql主库在同步的时候发生bin_log位置偏移,则通过下列命令刷新一下日志
show master status;
flush logs;
|