@@ -138,9 +138,16 @@ import (
138
138
" github.com/siddontang/go-mysql/client"
139
139
)
140
140
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
142
142
conn , _ := client.Connect (" 127.0.0.1:3306" , " root" , " " , " test" )
143
143
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
+
144
151
conn.Ping ()
145
152
146
153
// Insert
@@ -157,10 +164,17 @@ v, _ := r.GetInt(0, 0)
157
164
v, _ = r.GetIntByName (0 , " id" )
158
165
```
159
166
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
+
160
173
## Server
161
174
162
175
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.
164
178
165
179
### Example
166
180
@@ -174,14 +188,14 @@ l, _ := net.Listen("tcp", "127.0.0.1:4000")
174
188
175
189
c , _ := l.Accept ()
176
190
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.
179
193
conn , _ := server.NewConn (c, " root" , " " , server.EmptyHandler {})
180
194
181
195
for {
182
196
conn.HandleCommand ()
183
197
}
184
- ```
198
+ ```
185
199
186
200
Another shell
187
201
@@ -190,6 +204,15 @@ mysql -h127.0.0.1 -P4000 -uroot -p
190
204
//Becuase empty handler does nothing, so here the MySQL client can only connect the proxy server. :-)
191
205
```
192
206
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
+
193
216
## Failover
194
217
195
218
Failover supports to promote a new master and let other slaves replicate from it automatically when the old master was down.
0 commit comments