gomysql

Go语言MySQL数据库操作

倖福魔咒の 提交于 2020-12-18 19:13:27
一、MySQL数据库驱动 1、MySQL数据库驱动简介 Go语言官方没有实现MySQL数据库驱动,常用的开源MySQL数据库驱动实现如下: (1)Go MySQL Driver Go MySQL Driver支持database/sql接口,全部采用Go语言实现。 官方网站: https://github.com/go-sql-driver/mysql/ (2)MyMySQL MyMySQL支持database/sql接口,也支持自定义的接口,全部采用Go语言实现。 官方网站: https://github.com/ziutek/mymysql (3)GoMySQL GoMySQL不支持database/sql接口,采用自定义接口,全部采用Go语言实现。 官方网站: https://github.com/Philio/GoMySQL 2、Go-MySQL-Driver简介 Go-MySQL-Driver优点: (1)维护比较好。 (2)完全支持database/sql接口。 (3)支持keepalive,保持长连接。 Go-MySQL-Driver安装如下: go get github. com / go -sql-driver/mysql 导入包: import "database/sql" import _ "github.com/go-sql-driver/mysql" 二

聊聊kingbus的resp.go

我是研究僧i 提交于 2020-10-24 06:24:40
序 本文主要研究一下kingbus的resp.go writeOK kingbus/mysql/resp.go func (c *Conn) writeOK(r *gomysql.Result) error { if r == nil { r = &gomysql.Result{} } r.Status |= c.status data := make([]byte, 4, 32) data = append(data, gomysql.OK_HEADER) data = append(data, gomysql.PutLengthEncodedInt(r.AffectedRows)...) data = append(data, gomysql.PutLengthEncodedInt(r.InsertId)...) if c.capability&gomysql.CLIENT_PROTOCOL_41 > 0 { data = append(data, byte(r.Status), byte(r.Status>>8)) data = append(data, 0, 0) } return c.WritePacket(data) } writeOK方法写入gomysql.OK_HEADER writeError kingbus/mysql/resp.go func (c *Conn

聊聊kingbus的binlog_progress.go

对着背影说爱祢 提交于 2020-10-22 14:16:24
序 本文主要研究一下kingbus的binlog_progress.go BinlogProgress kingbus/server/binlog_progress.go //BinlogProgress is the progress of receiving binlog type BinlogProgress struct { currentGtid *atomic.String lastSaveGtid string //for heartbeat event lastBinlogFile *atomic.String lastFilePosition *atomic.Uint32 executedGtidSetStr *atomic.String trxBoundaryParser *mysql.TransactionBoundaryParser persistentTime time.Time persistentAppliedIndex uint64 executedGtidSet gomysql.GTIDSet store storage.Storage } BinlogProgress定义了currentGtid、lastSaveGtid、lastBinlogFile、lastFilePosition、executedGtidSetStr

聊聊kingbus的DumpBinlogAt

Deadly 提交于 2020-08-15 10:49:33
序 本文主要研究一下kingbus的DumpBinlogAt DumpBinlogAt kingbus/server/binlog_server.go //DumpBinlogAt implements dump binlog event by slave executed gtid set func (s *BinlogServer) DumpBinlogAt(ctx context.Context, startRaftIndex uint64, slaveGtids *gomysql.MysqlGTIDSet, eventC chan<- *storagepb.BinlogEvent, errorC chan<- error) error { var inExcludeGroup = false //new a binlog event reader from startRaftIndex, then send event to slave one by one reader, err := s.store.NewEntryReaderAt(startRaftIndex) if err != nil { log.Log.Errorf("NewEntryReaderAt error,err:%s,raftIndex:%d", err, startRaftIndex) return

聊聊kingbus的startMasterServer

元气小坏坏 提交于 2020-08-06 08:44:01
序 本文主要研究一下kingbus的startMasterServer startMasterServer kingbus/server/server.go func (s *KingbusServer) startMasterServer(args *config.BinlogServerConfig) error { master, err := NewBinlogServer(args, s, s.store, s.applyBroadcast) if err != nil { log.Log.Errorf("NewBinlogServer error,err:%s,args:%v", err, *args) return err } s.master = master s.master.Start() log.Log.Infof("startMasterServer success,args:%v", *args) return nil } startMasterServer方法先执行NewBinlogServer创建master,然后执行master的Start方法 NewBinlogServer kingbus/server/binlog_server.go //NewBinlogServer create a binlog server func