go-mysql library to avoid printing password in cleartext
This commit is contained in:
parent
83416fbb19
commit
fcda14634d
@ -41,7 +41,7 @@ func NewGoMySQLReader(connectionConfig *mysql.ConnectionConfig) (binlogReader *G
|
|||||||
|
|
||||||
serverId := uint32(binlogReader.MigrationContext.ReplicaServerId)
|
serverId := uint32(binlogReader.MigrationContext.ReplicaServerId)
|
||||||
|
|
||||||
binlogSyncerConfig := &replication.BinlogSyncerConfig{
|
binlogSyncerConfig := replication.BinlogSyncerConfig{
|
||||||
ServerID: serverId,
|
ServerID: serverId,
|
||||||
Flavor: "mysql",
|
Flavor: "mysql",
|
||||||
Host: connectionConfig.Key.Hostname,
|
Host: connectionConfig.Key.Hostname,
|
||||||
|
34
vendor/github.com/siddontang/go-mysql/README.md
generated
vendored
34
vendor/github.com/siddontang/go-mysql/README.md
generated
vendored
@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/siddontang/go-mysql/replication"
|
"github.com/siddontang/go-mysql/replication"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
// Create a binlog syncer with a unique server id, the server id must be different from other MySQL's.
|
// Create a binlog syncer with a unique server id, the server id must be different from other MySQL's.
|
||||||
// flavor is mysql or mariadb
|
// flavor is mysql or mariadb
|
||||||
cfg := replication.BinlogSyncerConfig {
|
cfg := replication.BinlogSyncerConfig {
|
||||||
ServerID: 100,
|
ServerID: 100,
|
||||||
@ -25,7 +25,7 @@ cfg := replication.BinlogSyncerConfig {
|
|||||||
User: "root",
|
User: "root",
|
||||||
Password: "",
|
Password: "",
|
||||||
}
|
}
|
||||||
syncer := replication.NewBinlogSyncer(&cfg)
|
syncer := replication.NewBinlogSyncer(cfg)
|
||||||
|
|
||||||
// Start sync with sepcified binlog file and position
|
// Start sync with sepcified binlog file and position
|
||||||
streamer, _ := syncer.StartSync(mysql.Position{binlogFile, binlogPos})
|
streamer, _ := syncer.StartSync(mysql.Position{binlogFile, binlogPos})
|
||||||
@ -85,13 +85,13 @@ Schema: test
|
|||||||
Query: DROP TABLE IF EXISTS `test_replication` /* generated by server */
|
Query: DROP TABLE IF EXISTS `test_replication` /* generated by server */
|
||||||
```
|
```
|
||||||
|
|
||||||
## Canal
|
## 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.
|
First, canal will dump your MySQL data then sync changed data using binlog incrementally.
|
||||||
|
|
||||||
You must use ROW format for binlog, full binlog row image is preferred, because we may meet some errors when primary key changed in update for minimal or noblob row image.
|
You must use ROW format for binlog, full binlog row image is preferred, because we may meet some errors when primary key changed in update for minimal or noblob row image.
|
||||||
|
|
||||||
A simple example:
|
A simple example:
|
||||||
|
|
||||||
@ -124,11 +124,11 @@ c.RegRowsEventHandler(&MyRowsEventHandler{})
|
|||||||
c.Start()
|
c.Start()
|
||||||
```
|
```
|
||||||
|
|
||||||
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/siddontang/go-mysql-elasticsearch) for how to sync MySQL data into Elasticsearch.
|
||||||
|
|
||||||
## Client
|
## Client
|
||||||
|
|
||||||
Client package supports a simple MySQL connection driver which you can use it to communicate with MySQL server.
|
Client package supports a simple MySQL connection driver which you can use it to communicate with MySQL server.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
@ -153,13 +153,13 @@ r, _ := conn.Execute(`select id, name from table where id = 1`)
|
|||||||
|
|
||||||
// Handle resultset
|
// Handle resultset
|
||||||
v, _ := r.GetInt(0, 0)
|
v, _ := r.GetInt(0, 0)
|
||||||
v, _ = r.GetIntByName(0, "id")
|
v, _ = r.GetIntByName(0, "id")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Server
|
## Server
|
||||||
|
|
||||||
Server package supplies a framework to implement a simple MySQL server which can handle the packets from the MySQL client.
|
Server package supplies a framework to implement a simple MySQL server which can handle the packets from the MySQL client.
|
||||||
You can use it to build your own MySQL proxy.
|
You can use it to build your own MySQL proxy.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
@ -185,8 +185,8 @@ for {
|
|||||||
Another shell
|
Another shell
|
||||||
|
|
||||||
```
|
```
|
||||||
mysql -h127.0.0.1 -P4000 -uroot -p
|
mysql -h127.0.0.1 -P4000 -uroot -p
|
||||||
//Becuase empty handler does nothing, so here the MySQL client can only connect the proxy server. :-)
|
//Becuase empty handler does nothing, so here the MySQL client can only connect the proxy server. :-)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Failover
|
## Failover
|
||||||
@ -195,10 +195,10 @@ Failover supports to promote a new master and let other slaves replicate from it
|
|||||||
|
|
||||||
Failover supports MySQL >= 5.6.9 with GTID mode, if you use lower version, e.g, MySQL 5.0 - 5.5, please use [MHA](http://code.google.com/p/mysql-master-ha/) or [orchestrator](https://github.com/outbrain/orchestrator).
|
Failover supports MySQL >= 5.6.9 with GTID mode, if you use lower version, e.g, MySQL 5.0 - 5.5, please use [MHA](http://code.google.com/p/mysql-master-ha/) or [orchestrator](https://github.com/outbrain/orchestrator).
|
||||||
|
|
||||||
At the same time, Failover supports MariaDB >= 10.0.9 with GTID mode too.
|
At the same time, Failover supports MariaDB >= 10.0.9 with GTID mode too.
|
||||||
|
|
||||||
Why only GTID? Supporting failover with no GTID mode is very hard, because slave can not find the proper binlog filename and position with the new master.
|
Why only GTID? Supporting failover with no GTID mode is very hard, because slave can not find the proper binlog filename and position with the new master.
|
||||||
Although there are many companies use MySQL 5.0 - 5.5, I think upgrade MySQL to 5.6 or higher is easy.
|
Although there are many companies use MySQL 5.0 - 5.5, I think upgrade MySQL to 5.6 or higher is easy.
|
||||||
|
|
||||||
## Driver
|
## Driver
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ We pass all tests in https://github.com/bradfitz/go-sql-test using go-mysql driv
|
|||||||
|
|
||||||
## Feedback
|
## Feedback
|
||||||
|
|
||||||
go-mysql is still in development, your feedback is very welcome.
|
go-mysql is still in development, your feedback is very welcome.
|
||||||
|
|
||||||
|
|
||||||
Gmail: siddontang@gmail.com
|
Gmail: siddontang@gmail.com
|
||||||
|
2
vendor/github.com/siddontang/go-mysql/canal/canal.go
generated
vendored
2
vendor/github.com/siddontang/go-mysql/canal/canal.go
generated
vendored
@ -265,7 +265,7 @@ func (c *Canal) prepareSyncer() error {
|
|||||||
Password: c.cfg.Password,
|
Password: c.cfg.Password,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.syncer = replication.NewBinlogSyncer(&cfg)
|
c.syncer = replication.NewBinlogSyncer(cfg)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
2
vendor/github.com/siddontang/go-mysql/cmd/go-mysqlbinlog/main.go
generated
vendored
2
vendor/github.com/siddontang/go-mysql/cmd/go-mysqlbinlog/main.go
generated
vendored
@ -45,7 +45,7 @@ func main() {
|
|||||||
SemiSyncEnabled: *semiSync,
|
SemiSyncEnabled: *semiSync,
|
||||||
}
|
}
|
||||||
|
|
||||||
b := replication.NewBinlogSyncer(&cfg)
|
b := replication.NewBinlogSyncer(cfg)
|
||||||
|
|
||||||
pos := mysql.Position{*file, uint32(*pos)}
|
pos := mysql.Position{*file, uint32(*pos)}
|
||||||
if len(*backupPath) > 0 {
|
if len(*backupPath) > 0 {
|
||||||
|
9
vendor/github.com/siddontang/go-mysql/replication/binlogsyncer.go
generated
vendored
9
vendor/github.com/siddontang/go-mysql/replication/binlogsyncer.go
generated
vendored
@ -54,7 +54,7 @@ type BinlogSyncerConfig struct {
|
|||||||
type BinlogSyncer struct {
|
type BinlogSyncer struct {
|
||||||
m sync.RWMutex
|
m sync.RWMutex
|
||||||
|
|
||||||
cfg *BinlogSyncerConfig
|
cfg BinlogSyncerConfig
|
||||||
|
|
||||||
c *client.Conn
|
c *client.Conn
|
||||||
|
|
||||||
@ -71,8 +71,13 @@ type BinlogSyncer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBinlogSyncer creates the BinlogSyncer with cfg.
|
// NewBinlogSyncer creates the BinlogSyncer with cfg.
|
||||||
func NewBinlogSyncer(cfg *BinlogSyncerConfig) *BinlogSyncer {
|
func NewBinlogSyncer(cfg BinlogSyncerConfig) *BinlogSyncer {
|
||||||
|
|
||||||
|
// Clear the Password to avoid outputing it in log.
|
||||||
|
pass := cfg.Password
|
||||||
|
cfg.Password = ""
|
||||||
log.Infof("create BinlogSyncer with config %v", cfg)
|
log.Infof("create BinlogSyncer with config %v", cfg)
|
||||||
|
cfg.Password = pass
|
||||||
|
|
||||||
b := new(BinlogSyncer)
|
b := new(BinlogSyncer)
|
||||||
|
|
||||||
|
6
vendor/github.com/siddontang/go-mysql/replication/replication_test.go
generated
vendored
6
vendor/github.com/siddontang/go-mysql/replication/replication_test.go
generated
vendored
@ -158,8 +158,8 @@ func (t *testSyncerSuite) testSync(c *C, s *BinlogStreamer) {
|
|||||||
t.testExecute(c, "DROP TABLE IF EXISTS test_json_v2")
|
t.testExecute(c, "DROP TABLE IF EXISTS test_json_v2")
|
||||||
|
|
||||||
str = `CREATE TABLE test_json_v2 (
|
str = `CREATE TABLE test_json_v2 (
|
||||||
id INT,
|
id INT,
|
||||||
c JSON,
|
c JSON,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
) ENGINE=InnoDB`
|
) ENGINE=InnoDB`
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ func (t *testSyncerSuite) setupTest(c *C, flavor string) {
|
|||||||
Password: "",
|
Password: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
t.b = NewBinlogSyncer(&cfg)
|
t.b = NewBinlogSyncer(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testSyncerSuite) testPositionSync(c *C) {
|
func (t *testSyncerSuite) testPositionSync(c *C) {
|
||||||
|
Loading…
Reference in New Issue
Block a user