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
Copy file name to clipboardExpand all lines: README.md
+39-11
Original file line number
Diff line number
Diff line change
@@ -40,8 +40,8 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac
40
40
* Optional placeholder interpolation
41
41
42
42
## Requirements
43
-
* Go 1.13 or higher. We aim to support the 3 latest versions of Go.
44
-
* MySQL (4.1+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
43
+
* Go 1.18 or higher. We aim to support the 3 latest versions of Go.
44
+
* MySQL (5.6+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
45
45
46
46
---------------------------------------
47
47
@@ -114,6 +114,12 @@ This has the same effect as an empty DSN string:
114
114
115
115
```
116
116
117
+
`dbname` is escaped by [PathEscape()]()https://pkg.go.dev/net/url#PathEscape) since v1.8.0. If your database name is `dbname/withslash`, it becomes:
118
+
119
+
```
120
+
/dbname%2Fwithslash
121
+
```
122
+
117
123
Alternatively, [Config.FormatDSN](https://godoc.org/github.com/go-sql-driver/mysql#Config.FormatDSN) can be used to create a DSN string by filling a struct.
118
124
119
125
#### Password
@@ -157,6 +163,17 @@ Default: false
157
163
158
164
`allowCleartextPasswords=true` allows using the [cleartext client side plugin](https://dev.mysql.com/doc/en/cleartext-pluggable-authentication.html) if required by an account, such as one defined with the [PAM authentication plugin](http://dev.mysql.com/doc/en/pam-authentication-plugin.html). Sending passwords in clear text may be a security problem in some configurations. To avoid problems if there is any possibility that the password would be intercepted, clients should connect to MySQL Server using a method that protects the password. Possibilities include [TLS / SSL](#tls), IPsec, or a private network.
159
165
166
+
167
+
##### `allowFallbackToPlaintext`
168
+
169
+
```
170
+
Type: bool
171
+
Valid Values: true, false
172
+
Default: false
173
+
```
174
+
175
+
`allowFallbackToPlaintext=true` acts like a `--ssl-mode=PREFERRED` MySQL client as described in [Command Options for Connecting to the Server](https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode)
176
+
160
177
##### `allowNativePasswords`
161
178
162
179
```
@@ -185,8 +202,7 @@ Default: none
185
202
186
203
Sets the charset used for client-server interaction (`"SET NAMES <value>"`). If multiple charsets are set (separated by a comma), the following charset is used if setting the charset failes. This enables for example support for `utf8mb4` ([introduced in MySQL 5.5.3](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)) with fallback to `utf8` for older servers (`charset=utf8mb4,utf8`).
187
204
188
-
Usage of the `charset` parameter is discouraged because it issues additional queries to the server.
189
-
Unless you need the fallback behavior, please use `collation` instead.
205
+
See also [Unicode Support](#unicode-support).
190
206
191
207
##### `checkConnLiveness`
192
208
@@ -215,6 +231,7 @@ The default collation (`utf8mb4_general_ci`) is supported from MySQL 5.5. You s
215
231
216
232
Collations for charset "ucs2", "utf16", "utf16le", and "utf32" can not be used ([ref](https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html#charset-connection-impermissible-client-charset)).
217
233
234
+
See also [Unicode Support](#unicode-support).
218
235
219
236
##### `clientFoundRows`
220
237
@@ -271,10 +288,10 @@ Please keep in mind, that param values must be [url.QueryEscape](https://golang.
271
288
##### `maxAllowedPacket`
272
289
```
273
290
Type: decimal number
274
-
Default: 4194304
291
+
Default: 64*1024*1024
275
292
```
276
293
277
-
Max packet size allowed in bytes. The default value is 4 MiB and should be adjusted to match the server settings. `maxAllowedPacket=0` can be used to automatically fetch the `max_allowed_packet` variable from server *on every connection*.
294
+
Max packet size allowed in bytes. The default value is 64 MiB and should be adjusted to match the server settings. `maxAllowedPacket=0` can be used to automatically fetch the `max_allowed_packet` variable from server *on every connection*.
278
295
279
296
##### `multiStatements`
280
297
@@ -284,9 +301,9 @@ Valid Values: true, false
284
301
Default: false
285
302
```
286
303
287
-
Allow multiple statements in one query. While this allows batch queries, it also greatly increases the risk of SQL injections. Only the result of the first query is returned, all other results are silently discarded.
304
+
Allow multiple statements in one query. This can be used to bach multiple queries. Use [Rows.NextResultSet()](https://pkg.go.dev/database/sql#Rows.NextResultSet) to get result of the second and subsequent queries.
288
305
289
-
When `multiStatements` is used, `?` parameters must only be used in the first statement.
306
+
When `multiStatements` is used, `?` parameters must only be used in the first statement.[interpolateParams](#interpolateparams) can be used to avoid this limitation unless prepared statement is used explicitly.
290
307
291
308
It's possible to access the last inserted ID and number of affected rows for multiple statements by using `sql.Conn.Raw()` and the `mysql.Result`. For example:
292
309
@@ -398,6 +415,15 @@ Default: 0
398
415
399
416
I/O write timeout. The value must be a decimal number with a unit suffix (*"ms"*, *"s"*, *"m"*, *"h"*), such as *"30s"*, *"0.5m"* or *"1m30s"*.
400
417
418
+
##### `connectionAttributes`
419
+
420
+
```
421
+
Type: comma-delimited string of user-defined "key:value" pairs
[Connection attributes](https://dev.mysql.com/doc/refman/8.0/en/performance-schema-connection-attribute-tables.html) are key-value pairs that application programs can pass to the server at connect time.
401
427
402
428
##### System Variables
403
429
@@ -470,7 +496,7 @@ user:password@/
470
496
The connection pool is managed by Go's database/sql package. For details on how to configure the size of the pool and how long connections stay in the pool see `*DB.SetMaxOpenConns`, `*DB.SetMaxIdleConns`, and `*DB.SetConnMaxLifetime` in the [database/sql documentation](https://golang.org/pkg/database/sql/). The read, write, and dial timeouts for each individual connection are configured with the DSN parameters [`readTimeout`](#readtimeout), [`writeTimeout`](#writetimeout), and [`timeout`](#timeout), respectively.
471
497
472
498
## `ColumnType` Support
473
-
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `BIGINT`.
499
+
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `MEDIUMINT`, `BIGINT`.
474
500
475
501
## `context.Context` Support
476
502
Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.
@@ -501,9 +527,11 @@ However, many want to scan MySQL `DATE` and `DATETIME` values into `time.Time` v
501
527
### Unicode support
502
528
Since version 1.5 Go-MySQL-Driver automatically uses the collation ` utf8mb4_general_ci` by default.
503
529
504
-
Other collations / charsets can be set using the [`collation`](#collation) DSN parameter.
530
+
Other charsets / collations can be set using the[`charset`](#charset) or[`collation`](#collation) DSN parameter.
505
531
506
-
Version 1.0 of the driver recommended adding `&charset=utf8` (alias for `SET NAMES utf8`) to the DSN to enable proper UTF-8 support. This is not necessary anymore. The [`collation`](#collation) parameter should be preferred to set another collation / charset than the default.
532
+
- When only the `charset` is specified, the `SET NAMES <charset>` query is sent and the server's default collation is used.
533
+
- When both the `charset` and `collation` are specified, the `SET NAMES <charset> COLLATE <collation>` query is sent.
534
+
- When only the `collation` is specified, the collation is specified in the protocol handshake and the `SET NAMES` query is not sent. This can save one roundtrip, but note that the server may ignore the specified collation silently and use the server's default charset/collation instead.
507
535
508
536
See http://dev.mysql.com/doc/refman/8.0/en/charset-unicode.html for more details on MySQL's Unicode support.
0 commit comments