Skip to content

Commit 8b47113

Browse files
michael2008siddontang
authored andcommitted
Add support for MySQL 8.0 and support for TLS/SSL for both Server and Client (go-mysql-org#312)
1 parent 319e088 commit 8b47113

Some content is hidden

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

66 files changed

+5330
-1089
lines changed

Gopkg.lock

+11-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@
2727

2828
[[constraint]]
2929
name = "github.com/BurntSushi/toml"
30-
version = "0.3.0"
30+
version = "v0.3.0"
3131

3232
[[constraint]]
3333
name = "github.com/go-sql-driver/mysql"
34-
version = "1.3.0"
34+
branch = "master"
3535

3636
[[constraint]]
3737
branch = "master"
3838
name = "github.com/juju/errors"
3939

4040
[[constraint]]
4141
name = "github.com/satori/go.uuid"
42-
version = "1.1.0"
42+
version = "v1.2.0"
4343

4444
[[constraint]]
4545
name = "github.com/shopspring/decimal"
46-
version = "1.0.0"
46+
version = "v1.1.0"
4747

4848
[[constraint]]
4949
branch = "master"

README.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,16 @@ import (
138138
"github.com/siddontang/go-mysql/client"
139139
)
140140

141-
// Connect MySQL at 127.0.0.1:3306, with user root, an empty passowrd and database test
141+
// Connect MySQL at 127.0.0.1:3306, with user root, an empty password and database test
142142
conn, _ := client.Connect("127.0.0.1:3306", "root", "", "test")
143143

144+
// Or to use SSL/TLS connection if MySQL server supports TLS
145+
//conn, _ := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.UseSSL(true)})
146+
147+
// or to set your own client-side certificates for identity verification for security
148+
//tlsConfig := NewClientTLSConfig(caPem, certPem, keyPem, false, "your-server-name")
149+
//conn, _ := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.SetTLSConfig(tlsConfig)})
150+
144151
conn.Ping()
145152

146153
// Insert
@@ -157,10 +164,17 @@ v, _ := r.GetInt(0, 0)
157164
v, _ = r.GetIntByName(0, "id")
158165
```
159166

167+
Tested MySQL versions for the client include:
168+
- 5.5.x
169+
- 5.6.x
170+
- 5.7.x
171+
- 8.0.x
172+
160173
## Server
161174

162175
Server package supplies a framework to implement a simple MySQL server which can handle the packets from the MySQL client.
163-
You can use it to build your own MySQL proxy.
176+
You can use it to build your own MySQL proxy. The server connection is compatible with MySQL 5.5, 5.6, 5.7, and 8.0 versions,
177+
so that most MySQL clients should be able to connect to the Server without modifications.
164178

165179
### Example
166180

@@ -174,14 +188,14 @@ l, _ := net.Listen("tcp", "127.0.0.1:4000")
174188

175189
c, _ := l.Accept()
176190

177-
// Create a connection with user root and an empty passowrd
178-
// We only an empty handler to handle command too
191+
// Create a connection with user root and an empty password.
192+
// You can use your own handler to handle command here.
179193
conn, _ := server.NewConn(c, "root", "", server.EmptyHandler{})
180194

181195
for {
182196
conn.HandleCommand()
183197
}
184-
```
198+
```
185199

186200
Another shell
187201

@@ -190,6 +204,15 @@ mysql -h127.0.0.1 -P4000 -uroot -p
190204
//Becuase empty handler does nothing, so here the MySQL client can only connect the proxy server. :-)
191205
```
192206

207+
> ```NewConn()``` will use default server configurations:
208+
> 1. automatically generate default server certificates and enable TLS/SSL support.
209+
> 2. support three mainstream authentication methods **'mysql_native_password'**, **'caching_sha2_password'**, and **'sha256_password'**
210+
> and use **'mysql_native_password'** as default.
211+
> 3. use an in-memory user credential provider to store user and password.
212+
>
213+
> To customize server configurations, use ```NewServer()``` and create connection via ```NewCustomizedConn()```.
214+
215+
193216
## Failover
194217

195218
Failover supports to promote a new master and let other slaves replicate from it automatically when the old master was down.

0 commit comments

Comments
 (0)