Skip to content

Commit

Permalink
Add support for MySQL 8.0 and support for TLS/SSL for both Server and…
Browse files Browse the repository at this point in the history
… Client (#312)
  • Loading branch information
michael2008 authored and siddontang committed Dec 21, 2018
1 parent 319e088 commit 8b47113
Show file tree
Hide file tree
Showing 66 changed files with 5,330 additions and 1,089 deletions.
16 changes: 11 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Gopkg.toml
Expand Up @@ -27,23 +27,23 @@

[[constraint]]
name = "github.com/BurntSushi/toml"
version = "0.3.0"
version = "v0.3.0"

[[constraint]]
name = "github.com/go-sql-driver/mysql"
version = "1.3.0"
branch = "master"

[[constraint]]
branch = "master"
name = "github.com/juju/errors"

[[constraint]]
name = "github.com/satori/go.uuid"
version = "1.1.0"
version = "v1.2.0"

[[constraint]]
name = "github.com/shopspring/decimal"
version = "1.0.0"
version = "v1.1.0"

[[constraint]]
branch = "master"
Expand Down
33 changes: 28 additions & 5 deletions README.md
Expand Up @@ -138,9 +138,16 @@ import (
"github.com/siddontang/go-mysql/client"
)

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

// Or to use SSL/TLS connection if MySQL server supports TLS
//conn, _ := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.UseSSL(true)})

// or to set your own client-side certificates for identity verification for security
//tlsConfig := NewClientTLSConfig(caPem, certPem, keyPem, false, "your-server-name")
//conn, _ := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.SetTLSConfig(tlsConfig)})

conn.Ping()

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

Tested MySQL versions for the client include:
- 5.5.x
- 5.6.x
- 5.7.x
- 8.0.x

## 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.
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,
so that most MySQL clients should be able to connect to the Server without modifications.

### Example

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

c, _ := l.Accept()

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

for {
conn.HandleCommand()
}
```
```

Another shell

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

> ```NewConn()``` will use default server configurations:
> 1. automatically generate default server certificates and enable TLS/SSL support.
> 2. support three mainstream authentication methods **'mysql_native_password'**, **'caching_sha2_password'**, and **'sha256_password'**
> and use **'mysql_native_password'** as default.
> 3. use an in-memory user credential provider to store user and password.
>
> To customize server configurations, use ```NewServer()``` and create connection via ```NewCustomizedConn()```.

## Failover

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

0 comments on commit 8b47113

Please sign in to comment.