Merge pull request #536 from github/go-mysql-ignore-pass

go-mysql library to avoid printing password in cleartext
This commit is contained in:
Shlomi Noach 2018-01-15 10:57:24 +02:00 committed by GitHub
commit ce4e42da32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 25 deletions

View File

@ -39,7 +39,7 @@ func NewGoMySQLReader(migrationContext *base.MigrationContext) (binlogReader *Go
serverId := uint32(migrationContext.ReplicaServerId)
binlogSyncerConfig := &replication.BinlogSyncerConfig{
binlogSyncerConfig := replication.BinlogSyncerConfig{
ServerID: serverId,
Flavor: "mysql",
Host: binlogReader.connectionConfig.Key.Hostname,

View File

@ -15,7 +15,7 @@ import (
"github.com/siddontang/go-mysql/replication"
"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
cfg := replication.BinlogSyncerConfig {
ServerID: 100,
@ -25,7 +25,7 @@ cfg := replication.BinlogSyncerConfig {
User: "root",
Password: "",
}
syncer := replication.NewBinlogSyncer(&cfg)
syncer := replication.NewBinlogSyncer(cfg)
// Start sync with sepcified binlog file and position
streamer, _ := syncer.StartSync(mysql.Position{binlogFile, binlogPos})
@ -85,13 +85,13 @@ Schema: test
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:
@ -124,11 +124,11 @@ c.RegRowsEventHandler(&MyRowsEventHandler{})
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 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
@ -153,13 +153,13 @@ r, _ := conn.Execute(`select id, name from table where id = 1`)
// Handle resultset
v, _ := r.GetInt(0, 0)
v, _ = r.GetIntByName(0, "id")
v, _ = r.GetIntByName(0, "id")
```
## Server
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.
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.
### Example
@ -185,8 +185,8 @@ for {
Another shell
```
mysql -h127.0.0.1 -P4000 -uroot -p
//Becuase empty handler does nothing, so here the MySQL client can only connect the proxy server. :-)
mysql -h127.0.0.1 -P4000 -uroot -p
//Becuase empty handler does nothing, so here the MySQL client can only connect the proxy server. :-)
```
## 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).
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.
Although there are many companies use MySQL 5.0 - 5.5, I think upgrade MySQL to 5.6 or higher is easy.
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.
## Driver
@ -223,7 +223,7 @@ We pass all tests in https://github.com/bradfitz/go-sql-test using go-mysql driv
## 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

View File

@ -265,7 +265,7 @@ func (c *Canal) prepareSyncer() error {
Password: c.cfg.Password,
}
c.syncer = replication.NewBinlogSyncer(&cfg)
c.syncer = replication.NewBinlogSyncer(cfg)
return nil
}

View File

@ -45,7 +45,7 @@ func main() {
SemiSyncEnabled: *semiSync,
}
b := replication.NewBinlogSyncer(&cfg)
b := replication.NewBinlogSyncer(cfg)
pos := mysql.Position{*file, uint32(*pos)}
if len(*backupPath) > 0 {

View File

@ -54,7 +54,7 @@ type BinlogSyncerConfig struct {
type BinlogSyncer struct {
m sync.RWMutex
cfg *BinlogSyncerConfig
cfg BinlogSyncerConfig
c *client.Conn
@ -71,8 +71,13 @@ type BinlogSyncer struct {
}
// 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)
cfg.Password = pass
b := new(BinlogSyncer)

View File

@ -158,8 +158,8 @@ func (t *testSyncerSuite) testSync(c *C, s *BinlogStreamer) {
t.testExecute(c, "DROP TABLE IF EXISTS test_json_v2")
str = `CREATE TABLE test_json_v2 (
id INT,
c JSON,
id INT,
c JSON,
PRIMARY KEY (id)
) ENGINE=InnoDB`
@ -271,7 +271,7 @@ func (t *testSyncerSuite) setupTest(c *C, flavor string) {
Password: "",
}
t.b = NewBinlogSyncer(&cfg)
t.b = NewBinlogSyncer(cfg)
}
func (t *testSyncerSuite) testPositionSync(c *C) {