Skip to content
/ Bristol Public
forked from brokercap/Bristol

模拟 MySQL 从库,实时解析 MySQL Binlog 的简单易用的库

Notifications You must be signed in to change notification settings

Lxuty/Bristol

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bristol ---- 模拟MySQL从库连接,监听MySQL binlog变更并解析

DDL 支持说明

当前只支持字段在表结构末尾追加新字段,如果配置的二进制位点是在DDL 之前的位点,会出现数据和字段对应不上 数据类型修改之后,如果配置的二进制位点是在DDL 之前的位点,可能会出现数据出错

类型转换

从Binlog解析出来的数据,在转成 map[string]interface{} 的数据格式的时候 MySQL里的存储类型对应Golang里的数据类型不一样 括号里的代表是Golang里的数据类型

  • - TINYINT ( int8 | unit8 )
  • - SMALLINT ( int16 | unit16 )
  • - MEDIUMINT ( int32 | uint32 )
  • - INT ( int32 | uint32 )
  • - BIGINT ( int64 | uint64 )
  • - FLOAT ( float32 )
  • - DOUBLE ( float64 )
  • - REAL ( float64 )
  • - DECIMAL , NUMERIC( 返回string类型 )
  • - DATE , TIME , YEAR , DATETIME , TIMESTAMP ( string )
  • - CHAR , VARCHAR ( string )
  • - TEXT , TINYTEXT , MEDIUMINTTEXT , - LONGTEXT ( string )
  • - BLOB, TINYBLOB , MEDIUMINTBLOB , LONGBLOB ( string )
  • - ENUM ( string )
  • - SET ( []string )
  • - BIT ( int64 )

使用案例

	filename := "mysql-bin.000071"

	var position uint32 = 203785789
	var DBsource = "root:root123@tcp(127.0.0.1:3306)/test"

	reslut := make(chan error, 1)
	m := make(map[string]uint8, 0)
	m["bifrost_test"] = 1
	m["mysql"] = 1
	BinlogDump := &mysql.BinlogDump{
		DataSource:    DBsource,
		CallbackFun:   callback,
		ReplicateDoDb: m,
		OnlyEvent:     []mysql.EventType{mysql.QUERY_EVENT, mysql.WRITE_ROWS_EVENTv1, mysql.UPDATE_ROWS_EVENTv1, mysql.DELETE_ROWS_EVENTv1,mysql.WRITE_ROWS_EVENTv2, mysql.UPDATE_ROWS_EVENTv2, mysql.DELETE_ROWS_EVENTv2},
	}
	go BinlogDump.StartDumpBinlog(filename, position, 100,reslut,"",0)
	go func() {
		for {
			v := <-reslut
			log.Printf("monitor reslut:%s \r\n", v)
		}
	}()

	for {
		time.Sleep(10 * time.Second)
	}

数据检验

请参考 一键数据检验测试工具

About

模拟 MySQL 从库,实时解析 MySQL Binlog 的简单易用的库

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 96.3%
  • TSQL 2.2%
  • Shell 1.5%