func (this *Binlog) Run(args []string) (exitCode int) { cmdFlags := flag.NewFlagSet("binlog", flag.ContinueOnError) cmdFlags.Usage = func() { this.Ui.Output(this.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 } cfg := &replication.BinlogSyncerConfig{ ServerID: 100, Flavor: "mysql", Host: "127.0.0.1", Port: 3306, User: "******", Password: "", } syncer := replication.NewBinlogSyncer(cfg) binlogFile := "mysql-bin.000080" binlogPos := uint32(1) stream, err := syncer.StartSync(mysql.Position{binlogFile, binlogPos}) if err != nil { panic(err) } for { evt, err := stream.GetEvent(context.Background()) if err != nil { panic(err) } evt.Dump(os.Stdout) } return }
func (this *Binlog) Run(args []string) (exitCode int) { cmdFlags := flag.NewFlagSet("binlog", flag.ContinueOnError) cmdFlags.Usage = func() { this.Ui.Output(this.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 } syncer := replication.NewBinlogSyncer(1001, "mysql") syncer.RegisterSlave("localhost", 3306, "root", "") binlogFile := "binlogFile" binlogPos := uint32(1) stream, err := syncer.StartSync(mysql.Position{binlogFile, binlogPos}) if err != nil { panic(err) } for { evt, err := stream.GetEvent() if err != nil { panic(err) } evt.Dump(os.Stdout) } return }
func NewGoMySQLReader(connectionConfig *mysql.ConnectionConfig) (binlogReader *GoMySQLReader, err error) { binlogReader = &GoMySQLReader{ connectionConfig: connectionConfig, currentCoordinates: mysql.BinlogCoordinates{}, currentCoordinatesMutex: &sync.Mutex{}, binlogSyncer: nil, binlogStreamer: nil, } binlogReader.binlogSyncer = replication.NewBinlogSyncer(serverId, "mysql") return binlogReader, err }
func main() { flag.Parse() b := replication.NewBinlogSyncer(101, *flavor) if err := b.RegisterSlave(*host, uint16(*port), *user, *password); err != nil { fmt.Printf("Register slave error: %v \n", errors.ErrorStack(err)) return } b.SetRawMode(*rawMode) if *semiSync { if err := b.EnableSemiSync(); err != nil { fmt.Printf("Enable semi sync replication mode err: %v\n", errors.ErrorStack(err)) return } } pos := mysql.Position{*file, uint32(*pos)} if len(*backupPath) > 0 { // must raw mode b.SetRawMode(true) err := b.StartBackup(*backupPath, pos, 0) if err != nil { fmt.Printf("Start backup error: %v\n", errors.ErrorStack(err)) return } } else { s, err := b.StartSync(pos) if err != nil { fmt.Printf("Start sync error: %v\n", errors.ErrorStack(err)) return } for { e, err := s.GetEvent() if err != nil { fmt.Printf("Get event error: %v\n", errors.ErrorStack(err)) return } e.Dump(os.Stdout) } } }
func (c *Canal) prepareSyncer() error { c.syncer = replication.NewBinlogSyncer(c.cfg.ServerID, c.cfg.Flavor) seps := strings.Split(c.cfg.Addr, ":") if len(seps) != 2 { return fmt.Errorf("invalid mysql addr format %s, must host:port", c.cfg.Addr) } port, err := strconv.ParseUint(seps[1], 10, 16) if err != nil { return err } if err = c.syncer.RegisterSlave(seps[0], uint16(port), c.cfg.User, c.cfg.Password); err != nil { return err } return nil }
func main() { flag.Parse() cfg := replication.BinlogSyncerConfig{ ServerID: 101, Flavor: *flavor, Host: *host, Port: uint16(*port), User: *user, Password: *password, RawModeEanbled: *rawMode, SemiSyncEnabled: *semiSync, } b := replication.NewBinlogSyncer(&cfg) pos := mysql.Position{*file, uint32(*pos)} if len(*backupPath) > 0 { // Backup will always use RawMode. err := b.StartBackup(*backupPath, pos, 0) if err != nil { fmt.Printf("Start backup error: %v\n", errors.ErrorStack(err)) return } } else { s, err := b.StartSync(pos) if err != nil { fmt.Printf("Start sync error: %v\n", errors.ErrorStack(err)) return } for { e, err := s.GetEvent(context.Background()) if err != nil { fmt.Printf("Get event error: %v\n", errors.ErrorStack(err)) return } e.Dump(os.Stdout) } } }