Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2tvenom/myreplication
Golang MySql binary log replication listener
https://github.com/2tvenom/myreplication
Last synced: about 1 month ago
JSON representation
Golang MySql binary log replication listener
- Host: GitHub
- URL: https://github.com/2tvenom/myreplication
- Owner: 2tvenom
- License: wtfpl
- Created: 2015-02-04T20:59:49.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-05T07:34:57.000Z (over 5 years ago)
- Last Synced: 2024-02-07T05:12:18.063Z (4 months ago)
- Language: Go
- Size: 80.1 KB
- Stars: 191
- Watchers: 20
- Forks: 49
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Database Tools)
- awesome-go-cn - myreplication
- awesome-go-extra - myreplication - 02-04T20:59:49Z|2018-10-05T07:34:57Z| (Generators / Database Tools)
- awesome-go-storage - myreplication - MySql binary log replication listener. Support statement and row based replication. (Database)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Database Tools)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Database Tools)
- fucking-awesome-go - :octocat: myreplication - MySql binary log replication listener. Support statement and row based replication. :star: 50 :fork_and_knife: 16 (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go-projects - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Standard CLI)
- awesome-go - myreplication - | - | - | (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Support statement and row based replication. (Database / Advanced Console UIs)
- awesome-go-with-framework - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Database Tools)
- go-awesome-cn-star - myreplication
- awesome-go - myreplication - MySql binary log replication listener. Support statement and row based replication. (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql二进制日志复制监听器。支持基于语句和行的复制。 (<span id="数据库-database">数据库 Database</span> / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go. - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go-cn - myreplication - MySql 二进制 log 复制监听器,支持基于语句和基于行的复制 (数据库 / 高级控制台界面)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-Char - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-reader - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go-storage - myreplication - MySql binary log replication listener. Support statement and row based replication. (Database)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go-cn - myreplication
- awesome-go - myreplication - MySql binary log replication listener. Support statement and row based replication. (Database / Advanced Console UIs)
- awesome-go-zh - myreplication
- awesome-go-handwritten - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql 二進制 log 複製監聽器,支持基於語句和基於行的複製 (數據庫 / 高級控制台界面)
- awesome-go - myreplication - Golang MySql binary log replication listener - ★ 122 (Database)
- awesome-go2 - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. - :arrow_down:0 - :star:58 (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Supports statement and row based replication. (Database / Advanced Console UIs)
- awesome-go - myreplication - MySql binary log replication listener. Support statement and row based replication. (Database / Advanced Console UIs)
- awesome-go-cn - myreplication
README
# Go MySql binary log replication listener
Pure Go Implementation of MySQL replication protocol. This allow you to receive event like insert, update, delete with their datas and raw SQL queries. This code has been developed and maintained by Ven at January 2015.
## Installation
```bash
go get github.com/2tvenom/myreplication
```## Test
The project is test with:
- Go 1.3.3
- MySQL 5.5, 5.6 and 5.7 (beta)
- Docker 1.4.1 build 5bc2ff8 (functional tests)It's not tested in real production situation.
### Unit tests
```bash
go test
```### Docker tests
Functonal tests with Docker. Test statement based and row based replication. MySql versions 5.5, 5.6, 5.7.
```bash
cd tests
sudo ./test.sh
```## MySQL server settings
In your MySQL server configuration file you need to enable replication:
[mysqld]
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
binlog-format = row #Row based replication## Example
```go
package mainimport (
"fmt"
"myreplication"
)var (
host = "localhost"
port = 3307
username = "admin"
password = "admin"
)func main() {
newConnection := myreplication.NewConnection()
serverId := uint32(2)
err := newConnection.ConnectAndAuth(host, port, username, password)if err != nil {
panic("Client not connected and not autentificate to master server with error:" + err.Error())
}
//Get position and file name
pos, filename, err := newConnection.GetMasterStatus()if err != nil {
panic("Master status fail: " + err.Error())
}el, err := newConnection.StartBinlogDump(pos, filename, serverId)
if err != nil {
panic("Cant start bin log: " + err.Error())
}
events := el.GetEventChan()
go func() {
for {
event := <-eventsswitch e := event.(type) {
case *myreplication.QueryEvent:
//Output query event
println(e.GetQuery())
case *myreplication.IntVarEvent:
//Output last insert_id if statement based replication
println(e.GetValue())
case *myreplication.WriteEvent:
//Output Write (insert) event
println("Write", e.GetTable())
//Rows loop
for i, row := range e.GetRows() {
//Columns loop
for j, col := range row {
//Output row number, column number, column type and column value
println(fmt.Sprintf("%d %d %d %v", i, j, col.GetType(), col.GetValue()))
}
}
case *myreplication.DeleteEvent:
//Output delete event
println("Delete", e.GetTable())
for i, row := range e.GetRows() {
for j, col := range row {
println(fmt.Sprintf("%d %d %d %v", i, j, col.GetType(), col.GetValue()))
}
}
case *myreplication.UpdateEvent:
//Output update event
println("Update", e.GetTable())
//Output old data before update
for i, row := range e.GetRows() {
for j, col := range row {
println(fmt.Sprintf("%d %d %d %v", i, j, col.GetType(), col.GetValue()))
}
}
//Output new
for i, row := range e.GetNewRows() {
for j, col := range row {
println(fmt.Sprintf("%d %d %d %v", i, j, col.GetType(), col.GetValue()))
}
}
default:
}
}
}()
err = el.Start()
println(err.Error())
}```
## Links
- MySql documentation http://dev.mysql.com/doc/internals/en/client-server-protocol.html
- Python implementation. MySql 5.6 checksum compatibility https://github.com/noplay/python-mysql-replication
- Go MySql client. Password encryption method https://github.com/ziutek/mymysql
- Java implementation. Decimal type parsing https://github.com/whitesock/open-replicator
- Ruby implementation. Decimal type parsing https://github.com/jeremycole/mysql_binlog
- Docker files https://github.com/docker-library/mysql
## Licence
[WTFPL](http://www.wtfpl.net/)