@@ -36,7 +36,7 @@ You can use it as a MySQL slave to sync binlog from master then do something, li
36
36
37
37
``` go
38
38
import (
39
- " github.com/siddontang /go-mysql/replication"
39
+ " github.com/go-mysql-org /go-mysql/replication"
40
40
" os"
41
41
)
42
42
// Create a binlog syncer with a unique server id, the server id must be different from other MySQL's.
@@ -120,20 +120,18 @@ You must use ROW format for binlog, full binlog row image is preferred, because
120
120
A simple example:
121
121
122
122
``` go
123
- cfg := NewDefaultConfig ()
124
- cfg.Addr = " 127.0.0.1:3306"
125
- cfg.User = " root"
126
- // We only care table canal_test in test db
127
- cfg.Dump .TableDB = " test"
128
- cfg.Dump .Tables = []string {" canal_test" }
123
+ package main
129
124
130
- c , err := NewCanal (cfg)
125
+ import (
126
+ " github.com/siddontang/go-log/log"
127
+ " github.com/go-mysql-org/go-mysql/canal"
128
+ )
131
129
132
130
type MyEventHandler struct {
133
- DummyEventHandler
131
+ canal. DummyEventHandler
134
132
}
135
133
136
- func (h *MyEventHandler ) OnRow (e *RowsEvent ) error {
134
+ func (h *MyEventHandler ) OnRow (e *canal . RowsEvent ) error {
137
135
log.Infof (" %s %v \n " , e.Action , e.Rows )
138
136
return nil
139
137
}
@@ -142,11 +140,25 @@ func (h *MyEventHandler) String() string {
142
140
return " MyEventHandler"
143
141
}
144
142
145
- // Register a handler to handle RowsEvent
146
- c.SetEventHandler (&MyEventHandler{})
143
+ func main () {
144
+ cfg := canal.NewDefaultConfig ()
145
+ cfg.Addr = " 127.0.0.1:3306"
146
+ cfg.User = " root"
147
+ // We only care table canal_test in test db
148
+ cfg.Dump .TableDB = " test"
149
+ cfg.Dump .Tables = []string {" canal_test" }
150
+
151
+ c , err := canal.NewCanal (cfg)
152
+ if err != nil {
153
+ log.Fatal (err)
154
+ }
155
+
156
+ // Register a handler to handle RowsEvent
157
+ c.SetEventHandler (&MyEventHandler{})
147
158
148
- // Start canal
149
- c.Run ()
159
+ // Start canal
160
+ c.Run ()
161
+ }
150
162
```
151
163
152
164
You can see [ go-mysql-elasticsearch] ( https://github.com/siddontang/go-mysql-elasticsearch ) for how to sync MySQL data into Elasticsearch.
@@ -159,7 +171,7 @@ Client package supports a simple MySQL connection driver which you can use it to
159
171
160
172
``` go
161
173
import (
162
- " github.com/siddontang /go-mysql/client"
174
+ " github.com/go-mysql-org /go-mysql/client"
163
175
)
164
176
165
177
// Connect MySQL at 127.0.0.1:3306, with user root, an empty password and database test
@@ -241,7 +253,7 @@ so that most MySQL clients should be able to connect to the Server without modif
241
253
242
254
``` go
243
255
import (
244
- " github.com/siddontang /go-mysql/server"
256
+ " github.com/go-mysql-org /go-mysql/server"
245
257
" net"
246
258
)
247
259
@@ -295,7 +307,7 @@ package main
295
307
import (
296
308
" database/sql"
297
309
298
- _ " github.com/siddontang /go-mysql/driver"
310
+ _ " github.com/go-mysql-org /go-mysql/driver"
299
311
)
300
312
301
313
func main () {
0 commit comments