forked from go-mysql-org/go-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bebe11e
commit c6896ff
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/siddontang/go-mysql/mysql" | ||
"github.com/siddontang/go-mysql/replication" | ||
"os" | ||
) | ||
|
||
var host = flag.String("host", "127.0.0.1", "MySQL host") | ||
var port = flag.Int("port", 3306, "MySQL port") | ||
var user = flag.String("user", "root", "MySQL user") | ||
var password = flag.String("password", "", "MySQL password") | ||
|
||
var flavor = flag.String("flavor", "mysql", "Flavor: mysql or mariadb") | ||
|
||
var file = flag.String("file", "", "Binlog filename") | ||
var pos = flag.Int("pos", 4, "Binlog position") | ||
|
||
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", err) | ||
return | ||
} | ||
|
||
s, err := b.StartSync(mysql.Position{*file, uint32(*pos)}) | ||
if err != nil { | ||
fmt.Printf("Start sync error: %v\n", err) | ||
return | ||
} | ||
|
||
for { | ||
e, err := s.GetEvent() | ||
if err != nil { | ||
fmt.Printf("Get event error: %v\n", err) | ||
return | ||
} | ||
|
||
e.Dump(os.Stdout) | ||
} | ||
} |