You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -38,15 +39,15 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac
38
39
* Optional placeholder interpolation
39
40
40
41
## Requirements
41
-
* Go 1.2 or higher
42
+
* Go 1.5 or higher
42
43
* MySQL (4.1+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
43
44
44
45
---------------------------------------
45
46
46
47
## Installation
47
48
Simple install the package to your [$GOPATH](https://github.com/golang/go/wiki/GOPATH"GOPATH") with the [go tool](https://golang.org/cmd/go/"go command") from shell:
48
49
```bash
49
-
$ go get github.com/go-sql-driver/mysql
50
+
$ go get -u github.com/go-sql-driver/mysql
50
51
```
51
52
Make sure [Git is installed](https://git-scm.com/downloads) on your machine and in your system's `PATH`.
52
53
@@ -100,7 +101,8 @@ See [net.Dial](https://golang.org/pkg/net/#Dial) for more information which netw
100
101
In general you should use an Unix domain socket if available and TCP otherwise for best performance.
101
102
102
103
#### Address
103
-
For TCP and UDP networks, addresses have the form `host:port`.
104
+
For TCP and UDP networks, addresses have the form `host[:port]`.
105
+
If `port` is omitted, the default port will be used.
104
106
If `host` is a literal IPv6 address, it must be enclosed in square brackets.
105
107
The functions [net.JoinHostPort](https://golang.org/pkg/net/#JoinHostPort) and [net.SplitHostPort](https://golang.org/pkg/net/#SplitHostPort) manipulate addresses in this form.
106
108
@@ -137,9 +139,9 @@ Default: false
137
139
```
138
140
Type: bool
139
141
Valid Values: true, false
140
-
Default: false
142
+
Default: true
141
143
```
142
-
`allowNativePasswords=true` allows the usage of the mysql native password method.
144
+
`allowNativePasswords=false` disallows the usage of MySQL native password method.
143
145
144
146
##### `allowOldPasswords`
145
147
@@ -267,19 +269,30 @@ Default: 0
267
269
268
270
I/O read timeout. The value must be a decimal number with a unit suffix (*"ms"*, *"s"*, *"m"*, *"h"*), such as *"30s"*, *"0.5m"* or *"1m30s"*.
269
271
270
-
##### `strict`
272
+
##### `rejectReadOnly`
271
273
272
274
```
273
275
Type: bool
274
276
Valid Values: true, false
275
277
Default: false
276
278
```
277
279
278
-
`strict=true` enables a driver-side strict mode in which MySQL warnings are treated as errors. This mode should not be used in production as it may lead to data corruption in certain situations.
279
280
280
-
A server-side strict mode, which is safe for production use, can be set via the [`sql_mode`](https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html) system variable.
281
+
`rejectreadOnly=true` causes the driver to reject read-only connections. This
282
+
is for a possible race condition during an automatic failover, where the mysql
283
+
client gets connected to a read-only replica after the failover.
284
+
285
+
Note that this should be a fairly rare case, as an automatic failover normally
286
+
happens when the primary is down, and the race condition shouldn't happen
287
+
unless it comes back up online as soon as the failover is kicked off. On the
288
+
other hand, when this happens, a MySQL application can get stuck on a
289
+
read-only connection until restarted. It is however fairly easy to reproduce,
290
+
for example, using a manual failover on AWS Aurora's MySQL-compatible cluster.
291
+
292
+
If you are not relying on read-only transactions to reject writes that aren't
293
+
supposed to happen, setting this on some MySQL providers (such as AWS Aurora)
294
+
is safer for failovers.
281
295
282
-
By default MySQL also treats notes as warnings. Use [`sql_notes=false`](http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_sql_notes) to ignore notes.
283
296
284
297
##### `timeout`
285
298
@@ -290,6 +303,7 @@ Default: OS default
290
303
291
304
Timeout for establishing connections, aka dial timeout. The value must be a decimal number with a unit suffix (*"ms"*, *"s"*, *"m"*, *"h"*), such as *"30s"*, *"0.5m"* or *"1m30s"*.
292
305
306
+
293
307
##### `tls`
294
308
295
309
```
@@ -300,6 +314,7 @@ Default: false
300
314
301
315
`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side). Use a custom value registered with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
302
316
317
+
303
318
##### `writeTimeout`
304
319
305
320
```
@@ -318,9 +333,9 @@ Any other parameters are interpreted as system variables:
* The values for string variables must be quoted with '
336
+
* The values for string variables must be quoted with `'`.
322
337
* The values must also be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed!
323
-
(which implies values of string variables must be wrapped with `%27`)
338
+
(which implies values of string variables must be wrapped with `%27`).
324
339
325
340
Examples:
326
341
*`autocommit=1`: `SET autocommit=1`
@@ -400,7 +415,7 @@ See the [godoc of Go-MySQL-Driver](https://godoc.org/github.com/go-sql-driver/my
400
415
401
416
402
417
### `time.Time` support
403
-
The default internal output type of MySQL `DATE` and `DATETIME` values is `[]byte` which allows you to scan the value into a `[]byte`, `string` or `sql.RawBytes` variable in your programm.
418
+
The default internal output type of MySQL `DATE` and `DATETIME` values is `[]byte` which allows you to scan the value into a `[]byte`, `string` or `sql.RawBytes` variable in your program.
404
419
405
420
However, many want to scan MySQL `DATE` and `DATETIME` values into `time.Time` variables, which is the logical opposite in Go to `DATE` and `DATETIME` in MySQL. You can do that by changing the internal output type from `[]byte` to `time.Time` with the DSN parameter `parseTime=true`. You can set the default [`time.Time` location](https://golang.org/pkg/time/#Location) with the `loc` DSN parameter.
406
421
@@ -418,6 +433,9 @@ Version 1.0 of the driver recommended adding `&charset=utf8` (alias for `SET NAM
418
433
419
434
See http://dev.mysql.com/doc/refman/5.7/en/charset-unicode.html for more details on MySQL's Unicode support.
420
435
436
+
## `context.Context` Support
437
+
Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.
438
+
See [context support in the database/sql package](https://golang.org/doc/go1.8#database_sql) for more details.
421
439
422
440
## Testing / Development
423
441
To run the driver tests you may need to adjust the configuration. See the [Testing Wiki-Page](https://github.com/go-sql-driver/mysql/wiki/Testing"Testing") for details.
@@ -437,13 +455,13 @@ Mozilla summarizes the license scope as follows:
437
455
438
456
439
457
That means:
440
-
* You can **use** the **unchanged** source code both in private and commercially
441
-
* When distributing, you **must publish** the source code of any **changed files** licensed under the MPL 2.0 under a) the MPL 2.0 itself or b) a compatible license (e.g. GPL 3.0 or Apache License 2.0)
442
-
* You **needn't publish** the source code of your library as long as the files licensed under the MPL 2.0 are **unchanged**
458
+
* You can **use** the **unchanged** source code both in private and commercially.
459
+
* When distributing, you **must publish** the source code of any **changed files** licensed under the MPL 2.0 under a) the MPL 2.0 itself or b) a compatible license (e.g. GPL 3.0 or Apache License 2.0).
460
+
* You **needn't publish** the source code of your library as long as the files licensed under the MPL 2.0 are **unchanged**.
443
461
444
462
Please read the [MPL 2.0 FAQ](https://www.mozilla.org/en-US/MPL/2.0/FAQ/) if you have further questions regarding the license.
445
463
446
-
You can read the full terms here: [LICENSE](https://raw.github.com/go-sql-driver/mysql/master/LICENSE)
464
+
You can read the full terms here: [LICENSE](https://raw.github.com/go-sql-driver/mysql/master/LICENSE).
447
465
448
466

0 commit comments