-
Notifications
You must be signed in to change notification settings - Fork 11
/
example.go
50 lines (41 loc) · 1008 Bytes
/
example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import "database/sql"
import "database/sql/driver"
import _ "go-mysql-binlog/mysql"
import "fmt"
const dataSource = "root@tcp(127.0.0.1:3306)/shopify_dev"
func OpenDB() *sql.DB {
db, err := sql.Open("mysql", dataSource)
if err != nil {
panic(err)
}
return db
}
type MysqlConnection interface {
DumpBinlog(filename string, position uint32) (driver.Rows, error)
}
func main() {
db := OpenDB()
defer db.Close()
var filename, binlog_do_db, binlog_ignore_db string
var position uint32
row := db.QueryRow("SHOW MASTER STATUS")
err := row.Scan(&filename, &position, &binlog_do_db, &binlog_ignore_db)
if err != nil {
panic(err)
}
fmt.Printf("filename: %v, position: %v\n", filename, position)
driver := db.Driver()
conn, err := driver.Open(dataSource)
if err != nil {
panic(err)
}
mysqlConn := conn.(MysqlConnection)
rows, err := mysqlConn.DumpBinlog(filename, position)
if err != nil {
panic(err)
}
if rows != nil {
fmt.Println("Got results from binlog")
}
}