Skip to content

Commit 205ab40

Browse files
authored
Merge branch 'master' into json-store-as-string
2 parents 9e43b63 + 06f9327 commit 205ab40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1895
-251
lines changed

CHANGELOG.md

+53
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
### Tag v1.4.0 (2021-12-15)
2+
* Fix that forget to readOK after writing. [#652](https://github.com/go-mysql-org/go-mysql/pull/652) ([lance6716](https://github.com/lance6716))
3+
* Packet: memory optimization for reading network packet. [#651](https://github.com/go-mysql-org/go-mysql/pull/651) ([zr-hebo](https://github.com/zr-hebo))
4+
* Add test for Conn.ExecuteSelectStreaming. [#649](https://github.com/go-mysql-org/go-mysql/pull/649) ([atercattus](https://github.com/atercattus))
5+
* Fix(server):java jdbc connect "Access denied for user 'root'@'127.0.0.1:3306' (using password: Yes). [#646](https://github.com/go-mysql-org/go-mysql/pull/646) ([pretty66](https://github.com/pretty66))
6+
* Reuse BytesBuffer in BinlogParser. [#644](https://github.com/go-mysql-org/go-mysql/pull/644) ([D3Hunter](https://github.com/D3Hunter))
7+
* Add ConnectWithDialer. [#643](https://github.com/go-mysql-org/go-mysql/pull/643) ([bakins](https://github.com/bakins))
8+
* Read auth_data_len from InitialHandshake packet instead of hard code. [#640](https://github.com/go-mysql-org/go-mysql/pull/640) ([guoyuanchao1202](https://github.com/guoyuanchao1202))
9+
* Fix: return error if error in packet. [#637](https://github.com/go-mysql-org/go-mysql/pull/637) ([btoonk](https://github.com/btoonk))
10+
* Fix ast.TruncateTableStmt node name assignment. [#630](https://github.com/go-mysql-org/go-mysql/pull/630) ([daledude](https://github.com/daledude))
11+
* Support insert argument type json.RawMessage. [#627](https://github.com/go-mysql-org/go-mysql/pull/627) ([domyway](https://github.com/domyway))
12+
* Adds parsing of IntVarEvents. [#624](https://github.com/go-mysql-org/go-mysql/pull/624) ([IvoGoman](https://github.com/IvoGoman))
13+
* Allow to set certain client-side capabilities. [#616](https://github.com/go-mysql-org/go-mysql/pull/616) ([skoef](https://github.com/skoef))
14+
* Add GTID-based replication to example. [#615](https://github.com/go-mysql-org/go-mysql/pull/615) ([lance6716](https://github.com/lance6716))
15+
* Support MYSQL_TYPE_JSON. [#614](https://github.com/go-mysql-org/go-mysql/pull/614) ([domyway](https://github.com/domyway))
16+
* Adds documentation for row-based replication flags. [#611](https://github.com/go-mysql-org/go-mysql/pull/611) ([IvoGoman](https://github.com/IvoGoman))
17+
* Add scheme/Index NoneUnique. [#610](https://github.com/go-mysql-org/go-mysql/pull/610) ([afocus](https://github.com/afocus))
18+
* Hidden mysql password in log. [#608](https://github.com/go-mysql-org/go-mysql/pull/608) ([elonzh](https://github.com/elonzh))
19+
* Fix error when trying to check binlog settings. [#602](https://github.com/go-mysql-org/go-mysql/pull/602) ([cr1sp1n](https://github.com/cr1sp1n))
20+
* Use constant and add comment for magic number 9. [#599](https://github.com/go-mysql-org/go-mysql/pull/599) ([lance6716](https://github.com/lance6716))
21+
* Extended ExecuteSelectStreaming. [#596](https://github.com/go-mysql-org/go-mysql/pull/596) ([skoef](https://github.com/skoef))
22+
* Fixed access denied error messages. [#595](https://github.com/go-mysql-org/go-mysql/pull/595) ([skoef](https://github.com/skoef))
23+
* Replaced all %lu, %ld and %u to %d for correct formatting of errors. [#594](https://github.com/go-mysql-org/go-mysql/pull/594) ([skoef](https://github.com/skoef))
24+
* Connection status flag manipulation. [#593](https://github.com/go-mysql-org/go-mysql/pull/593) ([skoef](https://github.com/skoef))
25+
* Return EOF response on COM_SET_OPTION commands. [#590](https://github.com/go-mysql-org/go-mysql/pull/590) ([skoef](https://github.com/skoef))
26+
* Improved access denied error messages. [#589](https://github.com/go-mysql-org/go-mysql/pull/589) ([skoef](https://github.com/skoef))
27+
* Expose capability and charset of connections to server. [#588](https://github.com/go-mysql-org/go-mysql/pull/588) ([skoef](https://github.com/skoef))
28+
* Fix a bug that values of time(1),time(3),time(5) will generate 00:00:00. [#529](https://github.com/go-mysql-org/go-mysql/pull/529) ([hamburgerbox](https://github.com/hamburgerbox))
29+
30+
### Tag v1.3.0 (2021.06.10)
31+
* Init Resultset in Result when handling ddl statement. [#578](https://github.com/go-mysql-org/go-mysql/pull/578) ([romberli](https://github.com/romberli))
32+
* Add pool for client connections. [#584](https://github.com/go-mysql-org/go-mysql/pull/584) ([atercattus](https://github.com/atercattus))
33+
34+
### Tag v1.2.1 (2021.05.27)
35+
* Prevent panic on malformed auth data. [#557](https://github.com/go-mysql-org/go-mysql/pull/557) ([timvaillancourt](https://github.com/timvaillancourt))
36+
37+
### Tag v1.2.0 (2021.05.16)
38+
* Fix a rare bug in Conn.readResultStreaming. [#573](https://github.com/go-mysql-org/go-mysql/pull/573) ([atercattus](https://github.com/atercattus))
39+
* Fix tag. [#575](https://github.com/go-mysql-org/go-mysql/pull/575) ([atercattus](https://github.com/atercattus))
40+
* Update dependency. [#576](https://github.com/go-mysql-org/go-mysql/pull/576) ([Ehco1996](https://github.com/Ehco1996))
41+
42+
### Tag v1.1.2 (2021.04.20)
43+
* Fix canal test in readme. [#516](https://github.com/go-mysql-org/go-mysql/pull/516) ([gaojijun](https://github.com/gaojijun))
44+
* UUID clone. [#522](https://github.com/go-mysql-org/go-mysql/pull/522) ([lance6716](https://github.com/lance6716))
45+
* Sort mariadb gtid set. [#545](https://github.com/go-mysql-org/go-mysql/pull/545) ([zeminzhou](https://github.com/zeminzhou))
46+
* Mysql: use numeric comparison for binlog filename. [#547](https://github.com/go-mysql-org/go-mysql/pull/547) ([lance6716](https://github.com/lance6716))
47+
* Fix MySQL spell. [#549](https://github.com/go-mysql-org/go-mysql/pull/549) ([igoso](https://github.com/igoso))
48+
* Update README.md and CHANGELOG.md. [#564](https://github.com/go-mysql-org/go-mysql/pull/564) ([atercattus](https://github.com/atercattus))
49+
* Update method now may receive strings with GTID sets. [#569](https://github.com/go-mysql-org/go-mysql/pull/569) ([mialinx](https://github.com/mialinx))
50+
* Change module name from siddontang/go-mysql to go-mysql-org/go-mysql. [#571](https://github.com/go-mysql-org/go-mysql/pull/571) ([lance6716](https://github.com/lance6716))
51+
* Fix a bug that not cloned to original memory. [#572](https://github.com/go-mysql-org/go-mysql/pull/572) ([lance6716](https://github.com/lance6716))
52+
* Update README.md for a new tag. [#574](https://github.com/go-mysql-org/go-mysql/pull/574) ([atercattus](https://github.com/atercattus))
53+
154
### Tag v1.1.1 (2021.04.08)
255
* Restructured dump/ tests. [#563](https://github.com/go-mysql-org/go-mysql/pull/563) ([atercattus](https://github.com/atercattus))
356
* Replace magic numbers in canal/canal_test.go by constants. [#562](https://github.com/go-mysql-org/go-mysql/pull/562) ([atercattus](https://github.com/atercattus))

README.md

+20-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ A pure go library to handle MySQL network protocol and replication.
99
## How to migrate to this repo
1010
To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`:
1111
```
12-
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.1.2
12+
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.4.0
1313
```
1414

15-
v1.1.2 - is the last tag in repo, feel free to choose what you want.
15+
v1.4.0 - is the last tag in repo, feel free to choose what you want.
1616

1717
## Changelog
1818
This repo uses [Changelog](CHANGELOG.md).
@@ -222,7 +222,7 @@ Tested MySQL versions for the client include:
222222
- 5.7.x
223223
- 8.0.x
224224

225-
### Example for SELECT streaming (v.1.1.1)
225+
### Example for SELECT streaming (v1.1.1)
226226
You can use also streaming for large SELECT responses.
227227
The callback function will be called for every result row without storing the whole resultset in memory.
228228
`result.Fields` will be filled before the first callback call.
@@ -237,12 +237,27 @@ err := conn.ExecuteSelectStreaming(`select id, name from table LIMIT 100500`, &r
237237
// Copy it if you need.
238238
// ...
239239
}
240-
return false, nil
241-
})
240+
return nil
241+
}, nil)
242242

243243
// ...
244244
```
245245

246+
### Example for connection pool (v1.3.0)
247+
248+
```go
249+
import (
250+
"github.com/go-mysql-org/go-mysql/client"
251+
)
252+
253+
pool := client.NewPool(log.Debugf, 100, 400, 5, "127.0.0.1:3306", `root`, ``, `test`)
254+
// ...
255+
conn, _ := pool.GetConn(ctx)
256+
defer pool.PutConn(conn)
257+
258+
conn.Execute() / conn.Begin() / etc...
259+
```
260+
246261
## Server
247262

248263
Server package supplies a framework to implement a simple MySQL server which can handle the packets from the MySQL client.

canal/canal.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (c *Canal) CheckBinlogRowImage(image string) error {
386386
// need to check MySQL binlog row image? full, minimal or noblob?
387387
// now only log
388388
if c.cfg.Flavor == mysql.MySQLFlavor {
389-
if res, err := c.Execute(`SHOW GLOBAL VARIABLES LIKE "binlog_row_image"`); err != nil {
389+
if res, err := c.Execute(`SHOW GLOBAL VARIABLES LIKE 'binlog_row_image'`); err != nil {
390390
return errors.Trace(err)
391391
} else {
392392
// MySQL has binlog row image from 5.6, so older will return empty
@@ -401,7 +401,7 @@ func (c *Canal) CheckBinlogRowImage(image string) error {
401401
}
402402

403403
func (c *Canal) checkBinlogRowFormat() error {
404-
res, err := c.Execute(`SHOW GLOBAL VARIABLES LIKE "binlog_format";`)
404+
res, err := c.Execute(`SHOW GLOBAL VARIABLES LIKE 'binlog_format';`)
405405
if err != nil {
406406
return errors.Trace(err)
407407
} else if f, _ := res.GetString(0, 1); f != "ROW" {

canal/sync.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func parseStmt(stmt ast.StmtNode) (ns []*node) {
223223
case *ast.TruncateTableStmt:
224224
n := &node{
225225
db: t.Table.Schema.String(),
226-
table: t.Table.Schema.String(),
226+
table: t.Table.Name.String(),
227227
}
228228
ns = []*node{n}
229229
}

client/auth.go

+27-14
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,25 @@ func (c *Conn) readInitialHandshake() error {
7777
c.capability = uint32(binary.LittleEndian.Uint16(data[pos:pos+2]))<<16 | c.capability
7878
pos += 2
7979

80-
// skip auth data len or [00]
80+
// auth_data is end with 0x00, min data length is 13 + 8 = 21
81+
// ref to https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake
82+
maxAuthDataLen := 21
83+
if c.capability&CLIENT_PLUGIN_AUTH != 0 && int(data[pos]) > maxAuthDataLen {
84+
maxAuthDataLen = int(data[pos])
85+
}
86+
8187
// skip reserved (all [00])
8288
pos += 10 + 1
8389

84-
// The documentation is ambiguous about the length.
85-
// The official Python library uses the fixed length 12
86-
// mysql-proxy also use 12
87-
// which is not documented but seems to work.
88-
c.salt = append(c.salt, data[pos:pos+12]...)
89-
pos += 13
90-
// auth plugin
91-
if end := bytes.IndexByte(data[pos:], 0x00); end != -1 {
92-
c.authPluginName = string(data[pos : pos+end])
93-
} else {
94-
c.authPluginName = string(data[pos:])
90+
// auth_data is end with 0x00, so we need to trim 0x00
91+
resetOfAuthDataEndPos := pos + maxAuthDataLen - 8 - 1
92+
c.salt = append(c.salt, data[pos:resetOfAuthDataEndPos]...)
93+
94+
// skip reset of end pos
95+
pos = resetOfAuthDataEndPos + 1
96+
97+
if c.capability&CLIENT_PLUGIN_AUTH != 0 {
98+
c.authPluginName = string(data[pos : len(data)-1])
9599
}
96100
}
97101

@@ -140,9 +144,18 @@ func (c *Conn) writeAuthHandshake() error {
140144
if !authPluginAllowed(c.authPluginName) {
141145
return fmt.Errorf("unknow auth plugin name '%s'", c.authPluginName)
142146
}
143-
// Adjust client capability flags based on server support
147+
148+
// Set default client capabilities that reflect the abilities of this library
144149
capability := CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION |
145-
CLIENT_LONG_PASSWORD | CLIENT_TRANSACTIONS | CLIENT_PLUGIN_AUTH | c.capability&CLIENT_LONG_FLAG
150+
CLIENT_LONG_PASSWORD | CLIENT_TRANSACTIONS | CLIENT_PLUGIN_AUTH
151+
// Adjust client capability flags based on server support
152+
capability |= c.capability & CLIENT_LONG_FLAG
153+
// Adjust client capability flags on specific client requests
154+
// Only flags that would make any sense setting and aren't handled elsewhere
155+
// in the library are supported here
156+
capability |= c.ccaps&CLIENT_FOUND_ROWS | c.ccaps&CLIENT_IGNORE_SPACE |
157+
c.ccaps&CLIENT_MULTI_STATEMENTS | c.ccaps&CLIENT_MULTI_RESULTS |
158+
c.ccaps&CLIENT_PS_MULTI_RESULTS | c.ccaps&CLIENT_CONNECT_ATTRS
146159

147160
// To enable TLS / SSL
148161
if c.tlsConfig != nil {

client/client_test.go

+49-24
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
11
package client
22

33
import (
4-
"flag"
4+
"encoding/json"
55
"fmt"
66
"strings"
7-
"testing"
87

9-
"github.com/go-mysql-org/go-mysql/test_util/test_keys"
108
. "github.com/pingcap/check"
119
"github.com/pingcap/errors"
1210

1311
"github.com/go-mysql-org/go-mysql/mysql"
12+
"github.com/go-mysql-org/go-mysql/test_util/test_keys"
1413
)
1514

16-
var testHost = flag.String("host", "127.0.0.1", "MySQL server host")
17-
18-
// We cover the whole range of MySQL server versions using docker-compose to bind them to different ports for testing.
19-
// MySQL is constantly updating auth plugin to make it secure:
20-
// starting from MySQL 8.0.4, a new auth plugin is introduced, causing plain password auth to fail with error:
21-
// ERROR 1251 (08004): Client does not support authentication protocol requested by server; consider upgrading MySQL client
22-
// Hint: use docker-compose to start corresponding MySQL docker containers and add the their ports here
23-
var testPort = flag.String("port", "3306", "MySQL server port") // choose one or more form 5561,5641,3306,5722,8003,8012,8013, e.g. '3306,5722,8003'
24-
var testUser = flag.String("user", "root", "MySQL user")
25-
var testPassword = flag.String("pass", "", "MySQL password")
26-
var testDB = flag.String("db", "test", "MySQL test database")
27-
28-
func Test(t *testing.T) {
29-
segs := strings.Split(*testPort, ",")
30-
for _, seg := range segs {
31-
Suite(&clientTestSuite{port: seg})
32-
}
33-
TestingT(t)
34-
}
35-
3615
type clientTestSuite struct {
3716
c *Conn
3817
port string
@@ -46,8 +25,10 @@ func (s *clientTestSuite) SetUpSuite(c *C) {
4625
c.Fatal(err)
4726
}
4827

49-
_, err = s.c.Execute("CREATE DATABASE IF NOT EXISTS " + *testDB)
28+
var result *mysql.Result
29+
result, err = s.c.Execute("CREATE DATABASE IF NOT EXISTS " + *testDB)
5030
c.Assert(err, IsNil)
31+
c.Assert(result.RowNumber() >= 0, IsTrue)
5132

5233
_, err = s.c.Execute("USE " + *testDB)
5334
c.Assert(err, IsNil)
@@ -82,6 +63,7 @@ func (s *clientTestSuite) testConn_CreateTable(c *C) {
8263
e enum("test1", "test2"),
8364
u tinyint unsigned,
8465
i tinyint,
66+
j json,
8567
PRIMARY KEY (id)
8668
) ENGINE=InnoDB DEFAULT CHARSET=utf8`
8769

@@ -94,6 +76,41 @@ func (s *clientTestSuite) TestConn_Ping(c *C) {
9476
c.Assert(err, IsNil)
9577
}
9678

79+
func (s *clientTestSuite) TestConn_SetCapability(c *C) {
80+
caps := []uint32{
81+
mysql.CLIENT_LONG_PASSWORD,
82+
mysql.CLIENT_FOUND_ROWS,
83+
mysql.CLIENT_LONG_FLAG,
84+
mysql.CLIENT_CONNECT_WITH_DB,
85+
mysql.CLIENT_NO_SCHEMA,
86+
mysql.CLIENT_COMPRESS,
87+
mysql.CLIENT_ODBC,
88+
mysql.CLIENT_LOCAL_FILES,
89+
mysql.CLIENT_IGNORE_SPACE,
90+
mysql.CLIENT_PROTOCOL_41,
91+
mysql.CLIENT_INTERACTIVE,
92+
mysql.CLIENT_SSL,
93+
mysql.CLIENT_IGNORE_SIGPIPE,
94+
mysql.CLIENT_TRANSACTIONS,
95+
mysql.CLIENT_RESERVED,
96+
mysql.CLIENT_SECURE_CONNECTION,
97+
mysql.CLIENT_MULTI_STATEMENTS,
98+
mysql.CLIENT_MULTI_RESULTS,
99+
mysql.CLIENT_PS_MULTI_RESULTS,
100+
mysql.CLIENT_PLUGIN_AUTH,
101+
mysql.CLIENT_CONNECT_ATTRS,
102+
mysql.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA,
103+
}
104+
105+
for _, cap := range caps {
106+
c.Assert(s.c.ccaps&cap > 0, IsFalse)
107+
s.c.SetCapability(cap)
108+
c.Assert(s.c.ccaps&cap > 0, IsTrue)
109+
s.c.UnsetCapability(cap)
110+
c.Assert(s.c.ccaps&cap > 0, IsFalse)
111+
}
112+
}
113+
97114
// NOTE for MySQL 5.5 and 5.6, server side has to config SSL to pass the TLS test, otherwise, it will throw error that
98115
// MySQL server does not support TLS required by the client. However, for MySQL 5.7 and above, auto generated certificates
99116
// are used by default so that manual config is no longer necessary.
@@ -149,6 +166,14 @@ func (s *clientTestSuite) TestConn_Insert(c *C) {
149166
c.Assert(pkg.AffectedRows, Equals, uint64(1))
150167
}
151168

169+
func (s *clientTestSuite) TestConn_Insert2(c *C) {
170+
str := `insert into mixer_test_conn (id, j) values(?, ?)`
171+
j := json.RawMessage(`[]`)
172+
pkg, err := s.c.Execute(str, []interface{}{2, j}...)
173+
c.Assert(err, IsNil)
174+
c.Assert(pkg.AffectedRows, Equals, uint64(1))
175+
}
176+
152177
func (s *clientTestSuite) TestConn_Select(c *C) {
153178
str := `select str, f, e from mixer_test_conn where id = 1`
154179

client/common_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package client
2+
3+
import (
4+
"flag"
5+
"strings"
6+
"testing"
7+
8+
. "github.com/pingcap/check"
9+
)
10+
11+
var testHost = flag.String("host", "127.0.0.1", "MySQL server host")
12+
13+
// We cover the whole range of MySQL server versions using docker-compose to bind them to different ports for testing.
14+
// MySQL is constantly updating auth plugin to make it secure:
15+
// starting from MySQL 8.0.4, a new auth plugin is introduced, causing plain password auth to fail with error:
16+
// ERROR 1251 (08004): Client does not support authentication protocol requested by server; consider upgrading MySQL client
17+
// Hint: use docker-compose to start corresponding MySQL docker containers and add the their ports here
18+
var testPort = flag.String("port", "3306", "MySQL server port") // choose one or more form 5561,5641,3306,5722,8003,8012,8013, e.g. '3306,5722,8003'
19+
var testUser = flag.String("user", "root", "MySQL user")
20+
var testPassword = flag.String("pass", "", "MySQL password")
21+
var testDB = flag.String("db", "test", "MySQL test database")
22+
23+
func Test(t *testing.T) {
24+
segs := strings.Split(*testPort, ",")
25+
for _, seg := range segs {
26+
Suite(&clientTestSuite{port: seg})
27+
Suite(&connTestSuite{port: seg})
28+
}
29+
TestingT(t)
30+
}

0 commit comments

Comments
 (0)