Giter VIP home page Giter VIP logo

go-canal's Introduction

GO-CANAL

Build Status codebeat badge Go Report Card codecov

简单配置,可将数据库变更记录投递到系统中

准备

  • 对于自建 MySQL , 需要先开启 Binlog 写入功能,配置 binlog-format 为 ROW 模式,my.cnf 中配置如下
[mysqld]
log-bin=mysql-bin # 开启 binlog
binlog-format=ROW # 选择 ROW 模式
server_id=1 # 配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复
  • 注意:针对阿里云 RDS for MySQL , 默认打开了 binlog , 并且账号默认具有 binlog dump 权限 , 不需要任何权限或者 binlog 设置,可以直接跳过这一步
  • 授权 canal 链接 MySQL 账号具有作为 MySQL slave 的权限, 如果已有账户可直接 grant
CREATE USER canal IDENTIFIED BY 'canal';  
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
-- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
FLUSH PRIVILEGES;

开始

  • 修改配置文件config.json
{
  "schema": [//监听订阅的库名
    "test_tt"
  ],
  "mysqlInfo": {//需要使用哪个MySQL用户去订阅mysql-bin
    "addr": "ip:3306",
    "user": "canal",
    "password": "canal"
  },
  "server": {//需要推送的tcp连接(需长链接)
    "network": "tcp",
    "addr": "ip:9501"
  }
}
  • 测试 -race不是必须的,选项用于检测数据竞争
go test -race 
  • 可以直接编译或直接运行项目,遇问题请提交issue
go build canal 
go run canal
直接运行
./canal 

后台挂起
nohup ./canal &
杀死进程
ps -aux|grep canal
得到pid后可以直接kill -9 
  • 推送成功消息示例
{
    "Action":"insert",   //行为 insert update delete
    "ColumnData":{},     //变更后的数据
    "SchemaName":"test", //库名
    "TableName":"test"   //表名
}

说明

  • 目前只支持Linux版本且 本地需要安装MySQL
  • TCP 断线重连默认3秒
  • MySQL 断线重连默认1秒

go-canal's People

Contributors

emmeair avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.