diff --git a/README.md b/README.md index 210b764de..5fed0b27f 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,34 @@ # go-mysql -A pure go library to handle MySQL network protocol and replication. +A pure go library to handle MySQL network protocol and replication as used by MySQL and MariaDB. ![semver](https://img.shields.io/github/v/tag/go-mysql-org/go-mysql) ![example workflow](https://github.com/go-mysql-org/go-mysql/actions/workflows/ci.yml/badge.svg) ![gomod version](https://img.shields.io/github/go-mod/go-version/go-mysql-org/go-mysql/master) - -## How to migrate to this repo -To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`: -``` -replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.10.0 -``` - -v1.10.0 - is the last tag in repo, feel free to choose what you want. +[![Go Reference](https://pkg.go.dev/badge/github.com/go-mysql-org/go-mysql.svg)](https://pkg.go.dev/github.com/go-mysql-org/go-mysql) ## Changelog This repo uses [Changelog](CHANGELOG.md). --- # Content -* [Replication](#replication) -* [Incremental dumping](#canal) -* [Client](#client) -* [Fake server](#server) -* [database/sql like driver](#driver) -* [Logging](#logging) +* [Replication](#replication) - Process events from a binlog stream. +* [Incremental dumping](#canal) - Sync from MySQL to Redis, Elasticsearch, etc. +* [Client](#client) - Simple MySQL client. +* [Fake server](#server) - server side of the MySQL protocol, as library. +* [database/sql like driver](#driver) - An alternative `database/sql` driver for MySQL. +* [Logging](#logging) - Custom logging options. +* [Migration](#how-to-migrate-to-this-repo) - Information for how to migrate if you used the old location of this project. + +## Examples + +The `cmd` directory contains example applications that can be build by running `make build` in the root of the project. The resulting binaries will be places in `bin/`. + +- `go-binlogparser`: parses a binlog file at a given offset +- `go-canal`: streams binlog events from a server to canal +- `go-mysqlbinlog`: streams binlog events +- `go-mysqldump`: like `mysqldump`, but in Go +- `go-mysqlserver`: fake MySQL server ## Replication @@ -55,9 +59,10 @@ syncer := replication.NewBinlogSyncer(cfg) streamer, _ := syncer.StartSync(mysql.Position{binlogFile, binlogPos}) // or you can start a gtid replication like +// gtidSet, _ := mysql.ParseGTIDSet(mysql.MySQLFlavor, "de278ad0-2106-11e4-9f8e-6edd0ca20947:1-2") // streamer, _ := syncer.StartSyncGTID(gtidSet) -// the mysql GTID set likes this "de278ad0-2106-11e4-9f8e-6edd0ca20947:1-2" -// the mariadb GTID set likes this "0-1-100" +// the mysql GTID set is like this "de278ad0-2106-11e4-9f8e-6edd0ca20947:1-2" and uses mysql.MySQLFlavor +// the mariadb GTID set is like this "0-1-100" and uses mysql.MariaDBFlavor for { ev, _ := streamer.GetEvent(context.Background()) @@ -111,7 +116,7 @@ Query: DROP TABLE IF EXISTS `test_replication` /* generated by server */ ## Canal -Canal is a package that can sync your MySQL into everywhere, like Redis, Elasticsearch. +Canal is a package that can sync your MySQL into everywhere, like Redis, Elasticsearch. First, canal will dump your MySQL data then sync changed data using binlog incrementally. @@ -161,7 +166,7 @@ func main() { } ``` -You can see [go-mysql-elasticsearch](https://github.com/siddontang/go-mysql-elasticsearch) for how to sync MySQL data into Elasticsearch. +You can see [go-mysql-elasticsearch](https://github.com/go-mysql-org/go-mysql-elasticsearch) for how to sync MySQL data into Elasticsearch. ## Client @@ -342,7 +347,7 @@ import ( func main() { // dsn format: "user:password@addr?dbname" dsn := "root@127.0.0.1:3306?test" - db, _ := sql.Open(dsn) + db, _ := sql.Open("mysql", dsn) db.Close() } ``` @@ -535,17 +540,19 @@ import "github.com/siddontang/go-log/log" Or you can implement your own [`log.Handler`](https://pkg.go.dev/github.com/siddontang/go-log/log#Handler). -## Donate - -If you like the project and want to buy me a cola, you can through: - -|PayPal|微信| -|------|---| -|[![](https://www.paypalobjects.com/webstatic/paypalme/images/pp_logo_small.png)](https://paypal.me/siddontang)|[![](https://github.com/siddontang/blog/blob/master/donate/weixin.png)| +## How to migrate to this repo +To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`: +``` +replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.10.0 +``` -## Feedback +This can be done by running this command: +``` +go mod edit -replace=github.com/siddontang/go-mysql=github.com/go-mysql-org/go-mysql@v1.10.0 +``` -go-mysql is still in development, your feedback is very welcome. +v1.10.0 - is the last tag in repo, feel free to choose what you want. +## Credits -Gmail: siddontang@gmail.com +go-mysql was started by @siddontang and has many [contributors](https://github.com/go-mysql-org/go-mysql/graphs/contributors)