{"id":13481484,"url":"https://github.com/2tvenom/myreplication","last_synced_at":"2025-04-30T08:33:57.861Z","repository":{"id":26860743,"uuid":"30320843","full_name":"2tvenom/myreplication","owner":"2tvenom","description":"Golang MySql binary log replication listener","archived":false,"fork":false,"pushed_at":"2018-10-05T07:34:57.000Z","size":82,"stargazers_count":193,"open_issues_count":5,"forks_count":48,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-10-30T15:50:50.920Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2tvenom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-04T20:59:49.000Z","updated_at":"2024-07-09T09:48:56.000Z","dependencies_parsed_at":"2022-07-27T09:02:30.990Z","dependency_job_id":null,"html_url":"https://github.com/2tvenom/myreplication","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2tvenom%2Fmyreplication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2tvenom%2Fmyreplication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2tvenom%2Fmyreplication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2tvenom%2Fmyreplication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2tvenom","download_url":"https://codeload.github.com/2tvenom/myreplication/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224203998,"owners_count":17273028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:00:52.235Z","updated_at":"2024-11-12T02:23:28.502Z","avatar_url":"https://github.com/2tvenom.png","language":"Go","funding_links":[],"categories":["Database","Go","数据库","数据库  `go语言实现的数据库`","數據庫","Uncategorized","Generators","\u003cspan id=\"数据库-database\"\u003e数据库 Database\u003c/span\u003e"],"sub_categories":["Advanced Console UIs","Database Tools","数据库工具","高级控制台界面","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"# Go MySql binary log replication listener\n\nPure 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.\n\n## Installation\n\n```bash\ngo get github.com/2tvenom/myreplication\n```\n\n## Test\n\nThe project is test with:\n\n - Go 1.3.3 \n - MySQL 5.5, 5.6 and 5.7 (beta)\n - Docker 1.4.1 build 5bc2ff8 (functional tests)\n\nIt's not tested in real production situation.\n\n### Unit tests\n```bash\ngo test\n```\n\n### Docker tests\n\nFunctonal tests with Docker. Test statement based and row based replication. MySql versions 5.5, 5.6, 5.7. \n\n```bash\ncd tests\nsudo ./test.sh\n```\n\n## MySQL server settings\n\nIn your MySQL server configuration file you need to enable replication:\n\n    [mysqld]\n    server-id\t\t = 1\n    log_bin\t\t\t = /var/log/mysql/mysql-bin.log\n    expire_logs_days = 10\n    max_binlog_size  = 100M\n    binlog-format    = row #Row based replication\n\n## Example\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"myreplication\"\n)\n\nvar (\n\thost     = \"localhost\"\n\tport     = 3307\n\tusername = \"admin\"\n\tpassword = \"admin\"\n)\n\nfunc main() {\n\tnewConnection := myreplication.NewConnection()\n\tserverId := uint32(2)\n\terr := newConnection.ConnectAndAuth(host, port, username, password)\n\n\tif err != nil {\n\t\tpanic(\"Client not connected and not autentificate to master server with error:\" + err.Error())\n\t}\n\t//Get position and file name\n\tpos, filename, err := newConnection.GetMasterStatus()\n\n\tif err != nil {\n\t\tpanic(\"Master status fail: \" + err.Error())\n\t}\n\n\tel, err := newConnection.StartBinlogDump(pos, filename, serverId)\n\n\tif err != nil {\n\t\tpanic(\"Cant start bin log: \" + err.Error())\n\t}\n\tevents := el.GetEventChan()\n\tgo func() {\n\t\tfor {\n\t\t\tevent := \u003c-events\n\n\t\t\tswitch e := event.(type) {\n\t\t\tcase *myreplication.QueryEvent:\n\t\t\t\t//Output query event\n\t\t\t\tprintln(e.GetQuery())\n\t\t\tcase *myreplication.IntVarEvent:\n\t\t\t\t//Output last insert_id  if statement based replication\n\t\t\t\tprintln(e.GetValue())\n\t\t\tcase *myreplication.WriteEvent:\n\t\t\t\t//Output Write (insert) event\n\t\t\t\tprintln(\"Write\", e.GetTable())\n\t\t\t\t//Rows loop\n\t\t\t\tfor i, row := range e.GetRows() {\n\t\t\t\t\t//Columns loop\n\t\t\t\t\tfor j, col := range row {\n\t\t\t\t\t\t//Output row number, column number, column type and column value\n\t\t\t\t\t\tprintln(fmt.Sprintf(\"%d %d %d %v\", i, j, col.GetType(), col.GetValue()))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase *myreplication.DeleteEvent:\n\t\t\t\t//Output delete event\n\t\t\t\tprintln(\"Delete\", e.GetTable())\n\t\t\t\tfor i, row := range e.GetRows() {\n\t\t\t\t\tfor j, col := range row {\n\t\t\t\t\t\tprintln(fmt.Sprintf(\"%d %d %d %v\", i, j, col.GetType(), col.GetValue()))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase *myreplication.UpdateEvent:\n\t\t\t\t//Output update event\n\t\t\t\tprintln(\"Update\", e.GetTable())\n\t\t\t\t//Output old data before update\n\t\t\t\tfor i, row := range e.GetRows() {\n\t\t\t\t\tfor j, col := range row {\n\t\t\t\t\t\tprintln(fmt.Sprintf(\"%d %d %d %v\", i, j, col.GetType(), col.GetValue()))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t//Output new\n\t\t\t\tfor i, row := range e.GetNewRows() {\n\t\t\t\t\tfor j, col := range row {\n\t\t\t\t\t\tprintln(fmt.Sprintf(\"%d %d %d %v\", i, j, col.GetType(), col.GetValue()))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t}()\n\terr = el.Start()\n\tprintln(err.Error())\n}\n\n```\n## Links\n - MySql documentation http://dev.mysql.com/doc/internals/en/client-server-protocol.html \n - Python implementation. MySql 5.6 checksum compatibility https://github.com/noplay/python-mysql-replication\n - Go MySql client. Password encryption method https://github.com/ziutek/mymysql\n - Java implementation. Decimal type parsing https://github.com/whitesock/open-replicator \n - Ruby implementation. Decimal type parsing https://github.com/jeremycole/mysql_binlog\n - Docker files https://github.com/docker-library/mysql\n \n\n## Licence\n[WTFPL](http://www.wtfpl.net/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2tvenom%2Fmyreplication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2tvenom%2Fmyreplication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2tvenom%2Fmyreplication/lists"}