Giter Site home page Giter Site logo

bristol's Introduction

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)
	}

数据检验

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

bristol's People

Contributors

jc3wish 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.