Skip to content

Commit 0151d26

Browse files
authored
Merge branch 'master' into float_with_trailing_zero
2 parents b358328 + 31aad20 commit 0151d26

28 files changed

+306
-157
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
go: [ "1.24", "1.23", "1.22" ]
14-
os: [ ubuntu-24.04, ubuntu-22.04 ]
13+
go: [ "1.24", "1.23" ]
14+
os: [ ubuntu-latest, ubuntu-24.04, ubuntu-22.04 ]
1515
name: Tests Go ${{ matrix.go }} on ${{ matrix.os }} # This name is used in main branch protection rules
1616
runs-on: ${{ matrix.os }}
1717

@@ -56,8 +56,9 @@ jobs:
5656
strategy:
5757
matrix:
5858
mysql_version:
59-
- 8.0.40
60-
- 8.4.3
59+
- 8.0.42
60+
- 8.4.5
61+
- 9.3.0
6162
name: Tests with MySQL ${{ matrix.mysql_version }}
6263
runs-on: ubuntu-latest
6364
services:
@@ -100,16 +101,19 @@ jobs:
100101
with:
101102
go-version: stable
102103
- name: golangci-lint
103-
uses: golangci/golangci-lint-action@v6
104+
uses: golangci/golangci-lint-action@v7
104105
with:
105106
version: latest
106107
args: --timeout=3m
107108

108109
platforms:
109110
strategy:
110111
matrix:
111-
arch: [ "amd64", "arm64" ]
112+
arch: [ "amd64", "arm64", "arm" ]
112113
os: [ "linux", "freebsd", "darwin" ]
114+
exclude:
115+
- arch: "arm"
116+
os: "darwin"
113117
name: platforms
114118
runs-on: ubuntu-latest
115119
steps:

.golangci.yml

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
1+
version: "2"
12
linters:
2-
disable-all: true
3+
default: none
34
enable:
4-
# All code is ready for:
55
- errcheck
6-
- gofumpt
7-
- goimports
86
- govet
9-
- gosimple
107
- ineffassign
118
- misspell
129
- nakedret
1310
- nolintlint
1411
- staticcheck
15-
- typecheck
1612
- unconvert
1713
- unused
1814
- whitespace
19-
# ToDo:
20-
#- gocritic
21-
#- golint
22-
linters-settings:
23-
nolintlint:
24-
allow-unused: false
25-
require-specific: true
26-
27-
govet:
28-
enable-all: true
29-
disable:
30-
- fieldalignment
31-
- lostcancel
32-
- shadow
33-
issues:
34-
exclude-files:
35-
- client/examples_test.go
15+
settings:
16+
govet:
17+
disable:
18+
- fieldalignment
19+
- lostcancel
20+
- shadow
21+
enable-all: true
22+
nolintlint:
23+
require-specific: true
24+
allow-unused: false
25+
exclusions:
26+
generated: lax
27+
presets:
28+
- comments
29+
- common-false-positives
30+
- legacy
31+
- std-error-handling
32+
paths:
33+
- client/examples_test.go
34+
- third_party$
35+
- builtin$
36+
- examples$
37+
formatters:
38+
enable:
39+
- gofumpt
40+
- goimports
41+
exclusions:
42+
generated: lax
43+
paths:
44+
- client/examples_test.go
45+
- third_party$
46+
- builtin$
47+
- examples$

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
### Tag v1.12.0 (2025-04-01)
2+
3+
> **Note:**
4+
> This version changes the logging framework to [`log/slog`](https://go.dev/blog/slog). If you use a custom logger then check the [Logging section](https://github.com/go-mysql-org/go-mysql?tab=readme-ov-file#logging) of the README.
5+
6+
* Server: Rework NewConn/defaultServer. [#1021](https://github.com/go-mysql-org/go-mysql/pull/1021) ([dveeden](https://github.com/dveeden))
7+
* Replication: add IsEmpty method to GTIDSet interface & implementations. [#1019](https://github.com/go-mysql-org/go-mysql/pull/1019) ([wesleywright](https://github.com/wesleywright))
8+
* Give `RowsEvent` a method to inspect the underlying event type.. [#1016](https://github.com/go-mysql-org/go-mysql/pull/1016) ([proton-lisandro-pin](https://github.com/proton-lisandro-pin))
9+
* Test: add test for TransactionPayloadEvent. [#1018](https://github.com/go-mysql-org/go-mysql/pull/1018) ([lance6716](https://github.com/lance6716))
10+
* CONTRIBUTING: Add note about testing locally. [#1014](https://github.com/go-mysql-org/go-mysql/pull/1014) ([dveeden](https://github.com/dveeden))
11+
* Replication: check hostname length. [#1013](https://github.com/go-mysql-org/go-mysql/pull/1013) ([dveeden](https://github.com/dveeden))
12+
* Initial contributor guide. [#1010](https://github.com/go-mysql-org/go-mysql/pull/1010) ([dveeden](https://github.com/dveeden))
13+
* Dump: Fix Unlick typo. [#1011](https://github.com/go-mysql-org/go-mysql/pull/1011) ([dveeden](https://github.com/dveeden))
14+
* Improve unit tests around `Hasresultset` and `WriteValue`. [#1006](https://github.com/go-mysql-org/go-mysql/pull/1006) ([stgarrity](https://github.com/stgarrity))
15+
* Replace github.com/siddontang/go-log with log/slog. [#993](https://github.com/go-mysql-org/go-mysql/pull/993) ([serprex](https://github.com/serprex))
16+
* Support MySQL vector type. [#1004](https://github.com/go-mysql-org/go-mysql/pull/1004) ([serprex](https://github.com/serprex))
17+
* Test: remove time-based checking. [#1002](https://github.com/go-mysql-org/go-mysql/pull/1002) ([lance6716](https://github.com/lance6716))
18+
* Replication: Add mysql::serialization based Gtid Log Event. [#990](https://github.com/go-mysql-org/go-mysql/pull/990) ([dveeden](https://github.com/dveeden))
19+
* Replication: Set `source_binlog_checksum` as well. [#1003](https://github.com/go-mysql-org/go-mysql/pull/1003) ([dveeden](https://github.com/dveeden))
20+
* Add support for MariaDB ED25519 plugin. [#998](https://github.com/go-mysql-org/go-mysql/pull/998) ([heavycrystal](https://github.com/heavycrystal))
21+
* Driver: context support. [#997](https://github.com/go-mysql-org/go-mysql/pull/997) ([serprex](https://github.com/serprex))
22+
* Use math/bits OnesCount to preallocate slices. [#995](https://github.com/go-mysql-org/go-mysql/pull/995) ([serprex](https://github.com/serprex))
23+
* Fix bug: context timeout inside for loop, it will case memory leak. [#999](https://github.com/go-mysql-org/go-mysql/pull/999) ([maaars](https://github.com/maaars))
24+
* Lint: gofumpt. [#996](https://github.com/go-mysql-org/go-mysql/pull/996) ([serprex](https://github.com/serprex))
25+
* Avoid utils.Now failing sometime around the year 2262. [#994](https://github.com/go-mysql-org/go-mysql/pull/994) ([serprex](https://github.com/serprex))
26+
* Client: Make example testable. [#987](https://github.com/go-mysql-org/go-mysql/pull/987) ([dveeden](https://github.com/dveeden))
27+
* CI: Update nolintlint config. [#991](https://github.com/go-mysql-org/go-mysql/pull/991) ([dveeden](https://github.com/dveeden))
28+
* CI: Remove Ubuntu 20.04. [#989](https://github.com/go-mysql-org/go-mysql/pull/989) ([dveeden](https://github.com/dveeden))
29+
* Server: Correctly handle `COM_STMT_EXECUTE` without rebind. [#984](https://github.com/go-mysql-org/go-mysql/pull/984) ([dveeden](https://github.com/dveeden))
30+
* README: add Platform Support section. [#981](https://github.com/go-mysql-org/go-mysql/pull/981) ([lance6716](https://github.com/lance6716))
31+
* Change how we import the mysql package. [#982](https://github.com/go-mysql-org/go-mysql/pull/982) ([dveeden](https://github.com/dveeden))
32+
* Server: Correct the check for Resultset. [#983](https://github.com/go-mysql-org/go-mysql/pull/983) ([dveeden](https://github.com/dveeden))
33+
* Client,mysql: Add support for Query Attributes. [#976](https://github.com/go-mysql-org/go-mysql/pull/976) ([dveeden](https://github.com/dveeden))
34+
* Use 4-byte UTF-8 by default. [#979](https://github.com/go-mysql-org/go-mysql/pull/979) ([dveeden](https://github.com/dveeden))
35+
* Client: Set `_client_version` connection attribute. [#978](https://github.com/go-mysql-org/go-mysql/pull/978) ([dveeden](https://github.com/dveeden))
36+
* Cleanup init functions. [#977](https://github.com/go-mysql-org/go-mysql/pull/977) ([serprex](https://github.com/serprex))
37+
* Server: set `CLIENT_CONNECT_ATTRS`. [#975](https://github.com/go-mysql-org/go-mysql/pull/975) ([dveeden](https://github.com/dveeden))
38+
* Mysql,client,driver: Add more docs/comments and update constants. [#974](https://github.com/go-mysql-org/go-mysql/pull/974) ([dveeden](https://github.com/dveeden))
39+
140
## Tag v1.11.0 (2025-01-23)
241
* Mysql: Fix GetInt() with negative NEWDECIMAL result. [#972](https://github.com/go-mysql-org/go-mysql/pull/972) ([dveeden](https://github.com/dveeden))
342
* Client: Update docs. [#970](https://github.com/go-mysql-org/go-mysql/pull/970) ([dveeden](https://github.com/dveeden))

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This library has been tested or deployed on the following operating systems and
1818
| Linux | amd64 ||| Check GitHub Actions of this project. |
1919
| Linux | s390x ||| A daily CI runs on an s390x VM, supported by the [IBM Z and LinuxONE Community](https://www.ibm.com/community/z/open-source/). |
2020
| Linux | arm64 ||| Deployed in a production environment of a user. |
21+
| Linux | arm ||| A test in CI to make sure builds for 32-bits platforms work. |
2122
| FreeBSD | amd64 ||| Sporadically tested by developers. |
2223

2324
Other platforms supported by Go may also work, but they have not been verified. Feel free to report your test results.
@@ -497,15 +498,15 @@ For the old logging package `github.com/siddontang/go-log/log`, a converting pac
497498
## How to migrate to this repo
498499
To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`:
499500
```
500-
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.11.0
501+
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.12.0
501502
```
502503

503504
This can be done by running this command:
504505
```
505-
go mod edit -replace=github.com/siddontang/go-mysql=github.com/go-mysql-org/go-mysql@v1.11.0
506+
go mod edit -replace=github.com/siddontang/go-mysql=github.com/go-mysql-org/go-mysql@v1.12.0
506507
```
507508

508-
v1.11.0 - is the last tag in repo, feel free to choose what you want.
509+
v1.12.0 - is the last tag in repo, feel free to choose what you want.
509510

510511
## Credits
511512

canal/sync.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,34 @@ func (c *Canal) WaitUntilPos(pos mysql.Position, timeout time.Duration) error {
324324
}
325325
}
326326

327-
func (c *Canal) GetMasterPos() (mysql.Position, error) {
328-
showBinlogStatus := "SHOW BINARY LOG STATUS"
329-
if eq, err := c.conn.CompareServerVersion("8.4.0"); (err == nil) && (eq < 0) {
330-
showBinlogStatus = "SHOW MASTER STATUS"
327+
// getShowBinaryLogQuery returns the correct SQL statement to query binlog status
328+
// for the given database flavor and server version.
329+
//
330+
// Sources:
331+
//
332+
// MySQL: https://dev.mysql.com/doc/relnotes/mysql/8.4/en/news-8-4-0.html
333+
// MariaDB: https://mariadb.com/kb/en/show-binlog-status
334+
func getShowBinaryLogQuery(flavor, serverVersion string) string {
335+
switch flavor {
336+
case mysql.MariaDBFlavor:
337+
eq, err := mysql.CompareServerVersions(serverVersion, "10.5.2")
338+
if (err == nil) && (eq >= 0) {
339+
return "SHOW BINLOG STATUS"
340+
}
341+
case mysql.MySQLFlavor:
342+
eq, err := mysql.CompareServerVersions(serverVersion, "8.4.0")
343+
if (err == nil) && (eq >= 0) {
344+
return "SHOW BINARY LOG STATUS"
345+
}
331346
}
332347

333-
rr, err := c.Execute(showBinlogStatus)
348+
return "SHOW MASTER STATUS"
349+
}
350+
351+
func (c *Canal) GetMasterPos() (mysql.Position, error) {
352+
query := getShowBinaryLogQuery(c.cfg.Flavor, c.conn.GetServerVersion())
353+
354+
rr, err := c.Execute(query)
334355
if err != nil {
335356
return mysql.Position{}, errors.Trace(err)
336357
}

canal/sync_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package canal
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestGetShowBinaryLogQuery(t *testing.T) {
10+
tests := []struct {
11+
flavor string
12+
serverVersion string
13+
expected string
14+
}{
15+
{flavor: "mariadb", serverVersion: "10.5.2", expected: "SHOW BINLOG STATUS"},
16+
{flavor: "mariadb", serverVersion: "10.6.0", expected: "SHOW BINLOG STATUS"},
17+
{flavor: "mariadb", serverVersion: "10.4.0", expected: "SHOW MASTER STATUS"},
18+
{flavor: "mysql", serverVersion: "8.4.0", expected: "SHOW BINARY LOG STATUS"},
19+
{flavor: "mysql", serverVersion: "8.4.1", expected: "SHOW BINARY LOG STATUS"},
20+
{flavor: "mysql", serverVersion: "8.0.33", expected: "SHOW MASTER STATUS"},
21+
{flavor: "mysql", serverVersion: "5.7.41", expected: "SHOW MASTER STATUS"},
22+
{flavor: "other", serverVersion: "1.0.0", expected: "SHOW MASTER STATUS"},
23+
}
24+
25+
for _, tt := range tests {
26+
t.Run(tt.flavor+"_"+tt.serverVersion, func(t *testing.T) {
27+
got := getShowBinaryLogQuery(tt.flavor, tt.serverVersion)
28+
require.Equal(t, tt.expected, got)
29+
})
30+
}
31+
}

client/conn.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ func ConnectWithDialer(ctx context.Context, network, addr, user, password, dbNam
152152

153153
c.Conn = packet.NewConnWithTimeout(conn, c.ReadTimeout, c.WriteTimeout, c.BufferSize)
154154
if c.tlsConfig != nil {
155-
seq := c.Conn.Sequence
155+
seq := c.Sequence
156156
c.Conn = packet.NewTLSConnWithTimeout(conn, c.ReadTimeout, c.WriteTimeout)
157-
c.Conn.Sequence = seq
157+
c.Sequence = seq
158158
}
159159

160160
if err = c.handshake(); err != nil {
@@ -163,9 +163,9 @@ func ConnectWithDialer(ctx context.Context, network, addr, user, password, dbNam
163163
}
164164

165165
if c.ccaps&mysql.CLIENT_COMPRESS > 0 {
166-
c.Conn.Compression = mysql.MYSQL_COMPRESS_ZLIB
166+
c.Compression = mysql.MYSQL_COMPRESS_ZLIB
167167
} else if c.ccaps&mysql.CLIENT_ZSTD_COMPRESSION_ALGORITHM > 0 {
168-
c.Conn.Compression = mysql.MYSQL_COMPRESS_ZSTD
168+
c.Compression = mysql.MYSQL_COMPRESS_ZSTD
169169
}
170170

171171
// if a collation was set with a ID of > 255, then we need to call SET NAMES ...

client/conn_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ func (s *connTestSuite) TestExecuteMultiple() {
119119
// also, since this is not the last query, the SERVER_MORE_RESULTS_EXISTS
120120
// flag should be set
121121
require.True(s.T(), result.Status&mysql.SERVER_MORE_RESULTS_EXISTS > 0)
122-
require.Equal(s.T(), 0, result.Resultset.RowNumber())
122+
require.Equal(s.T(), 0, result.RowNumber())
123123
require.Equal(s.T(), uint64(1), result.AffectedRows)
124124
require.NoError(s.T(), err)
125125
case 1:
126126
// the SELECT query should have an resultset
127127
// still not the last query, flag should be set
128128
require.True(s.T(), result.Status&mysql.SERVER_MORE_RESULTS_EXISTS > 0)
129-
require.Greater(s.T(), result.Resultset.RowNumber(), 0)
129+
require.Greater(s.T(), result.RowNumber(), 0)
130130
require.NoError(s.T(), err)
131131
case 3:
132132
// this query is obviously bogus so the error should be non-nil
@@ -175,7 +175,7 @@ func (s *connTestSuite) TestExecuteSelectStreaming() {
175175
// result.Resultset must be defined at this point
176176
require.NotNil(s.T(), result.Resultset)
177177
// Check number of columns
178-
require.Len(s.T(), result.Resultset.Fields, colsInResult)
178+
require.Len(s.T(), result.Fields, colsInResult)
179179

180180
perResultCallbackCalledTimes++
181181
return nil

client/resp.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,16 @@ func (c *Conn) handleAuthResult() error {
121121
}
122122

123123
// handle caching_sha2_password
124-
if c.authPluginName == mysql.AUTH_CACHING_SHA2_PASSWORD {
124+
switch c.authPluginName {
125+
case mysql.AUTH_CACHING_SHA2_PASSWORD:
125126
if data == nil {
126127
return nil // auth already succeeded
127128
}
128-
if data[0] == mysql.CACHE_SHA2_FAST_AUTH {
129+
switch data[0] {
130+
case mysql.CACHE_SHA2_FAST_AUTH:
129131
_, err = c.readOK()
130132
return err
131-
} else if data[0] == mysql.CACHE_SHA2_FULL_AUTH {
133+
case mysql.CACHE_SHA2_FULL_AUTH:
132134
// need full authentication
133135
if c.tlsConfig != nil || c.proto == "unix" {
134136
if err = c.WriteClearAuthPacket(c.password); err != nil {
@@ -141,10 +143,10 @@ func (c *Conn) handleAuthResult() error {
141143
}
142144
_, err = c.readOK()
143145
return err
144-
} else {
146+
default:
145147
return errors.Errorf("invalid packet %x", data[0])
146148
}
147-
} else if c.authPluginName == mysql.AUTH_SHA256_PASSWORD {
149+
case mysql.AUTH_SHA256_PASSWORD:
148150
if len(data) == 0 {
149151
return nil // auth already succeeded
150152
}
@@ -205,11 +207,12 @@ func (c *Conn) readOK() (*mysql.Result, error) {
205207
return nil, errors.Trace(err)
206208
}
207209

208-
if data[0] == mysql.OK_HEADER {
210+
switch data[0] {
211+
case mysql.OK_HEADER:
209212
return c.handleOKPacket(data)
210-
} else if data[0] == mysql.ERR_HEADER {
213+
case mysql.ERR_HEADER:
211214
return nil, c.handleErrorPacket(data)
212-
} else {
215+
default:
213216
return nil, errors.New("invalid ok packet")
214217
}
215218
}
@@ -310,7 +313,7 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *mysql.Re
310313
}
311314

312315
// this is a streaming resultset
313-
result.Resultset.Streaming = mysql.StreamingSelect
316+
result.Streaming = mysql.StreamingSelect
314317

315318
if err := c.readResultColumns(result); err != nil {
316319
return errors.Trace(err)
@@ -327,7 +330,7 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *mysql.Re
327330
}
328331

329332
// this resultset is done streaming
330-
result.Resultset.StreamingDone = true
333+
result.StreamingDone = true
331334

332335
return nil
333336
}

cmd/go-mysqlserver/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ func main() {
2626

2727
// Create a connection with user root and an empty password.
2828
// You can use your own handler to handle command here.
29-
conn, err := server.NewConn(c, "root", "", server.EmptyHandler{})
29+
srv := server.NewDefaultServer()
30+
conn, err := srv.NewConn(c, "root", "", server.EmptyHandler{})
3031
if err != nil {
3132
log.Fatal(err)
3233
}

0 commit comments

Comments
 (0)