Skip to content

Commit 589f54c

Browse files
committed
New parameter documentation
1 parent 58ac805 commit 589f54c

File tree

1 file changed

+123
-19
lines changed

1 file changed

+123
-19
lines changed

README.md

Lines changed: 123 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ Except for the databasename, all values are optional. So the minimal DSN is:
8686
If you do not want to preselect a database, leave `dbname` empty:
8787
```
8888
/
89+
```
90+
This has the same effect as an empty DSN string:
91+
```
92+
8993
```
9094

9195
#### Password
@@ -103,40 +107,140 @@ The functions [net.JoinHostPort](http://golang.org/pkg/net/#JoinHostPort) and [n
103107
For Unix domain sockets the address is the absolute path to the MySQL-Server-socket, e.g. `/var/run/mysqld/mysqld.sock` or `/tmp/mysql.sock`.
104108

105109
#### Parameters
106-
***Parameters are case-sensitive!***
107-
108-
Possible Parameters are:
109-
* `allowAllFiles`: `allowAllFiles=true` disables the file Whitelist for `LOAD DATA LOCAL INFILE` and allows *all* files. [*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)
110-
* `allowOldPasswords`: `allowAllFiles=true` allows the usage of the insecure old password method. This should be avoided, but is necessary in some cases. See also [the old_passwords wiki page](https://github.com/go-sql-driver/mysql/wiki/old_passwords).
111-
* `charset`: 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 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`).
112-
* `clientFoundRows`: `clientFoundRows=true` causes an UPDATE to return the number of matching rows instead of the number of rows changed.
113-
* `loc`: Sets the location for time.Time values (when using `parseTime=true`). The default is `UTC`. *"Local"* sets the system's location. See [time.LoadLocation](http://golang.org/pkg/time/#LoadLocation) for details. Please keep in mind, that param values must be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed. Alternatively you can manually replace the `/` with `%2F`. For example `US/Pacific` would be `US%2FPacific`.
114-
* `parseTime`: `parseTime=true` changes the output type of `DATE` and `DATETIME` values to `time.Time` instead of `[]byte` / `string`
115-
* `strict`: Enable strict mode. MySQL warnings are treated as errors.
116-
* `timeout`: **Driver** side connection timeout. The value must be a string of decimal numbers, each with optional fraction and a unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*. To set a server side timeout, use the parameter [`wait_timeout`](http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_wait_timeout).
117-
* `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`](http://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
110+
*Parameters are case-sensitive!*
111+
112+
##### `allowAllFiles`
113+
114+
```
115+
Type: bool
116+
Valid Values: true, false
117+
Default: false
118+
```
119+
120+
`allowAllFiles=true` disables the file Whitelist for `LOAD DATA LOCAL INFILE` and allows *all* files.
121+
[*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)
122+
123+
##### `allowOldPasswords`
124+
125+
```
126+
Type: bool
127+
Valid Values: true, false
128+
Default: false
129+
```
130+
`allowAllFiles=true` allows the usage of the insecure old password method. This should be avoided, but is necessary in some cases. See also [the old_passwords wiki page](https://github.com/go-sql-driver/mysql/wiki/old_passwords).
131+
132+
##### `charset`
133+
134+
```
135+
Type: string
136+
Valid Values: <name>
137+
Default: none
138+
```
139+
140+
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 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`).
141+
142+
143+
##### `clientFoundRows`
144+
145+
```
146+
Type: bool
147+
Valid Values: true, false
148+
Default: false
149+
```
150+
151+
`clientFoundRows=true` causes an UPDATE to return the number of matching rows instead of the number of rows changed.
152+
153+
154+
##### `loc`
155+
156+
```
157+
Type: string
158+
Valid Values: <escaped name>
159+
Default: UTC
160+
```
161+
162+
Sets the location for time.Time values (when using `parseTime=true`). *"Local"* sets the system's location. See [time.LoadLocation](http://golang.org/pkg/time/#LoadLocation) for details.
163+
164+
Please keep in mind, that param values must be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed. Alternatively you can manually replace the `/` with `%2F`. For example `US/Pacific` would be `loc=US%2FPacific`.
165+
166+
167+
##### `parseTime`
168+
169+
```
170+
Type: bool
171+
Valid Values: true, false
172+
Default: false
173+
```
174+
175+
`parseTime=true` changes the output type of `DATE` and `DATETIME` values to `time.Time` instead of `[]byte` / `string`
176+
177+
178+
##### `strict`
179+
180+
```
181+
Type: bool
182+
Valid Values: true, false
183+
Default: false
184+
```
185+
186+
`strict=true` enables strict mode. MySQL warnings are treated as errors.
187+
188+
189+
##### `timeout`
190+
191+
```
192+
Type: decimal number
193+
Default: OS default
194+
```
195+
196+
*Driver* side connection timeout. The value must be a string of decimal numbers, each with optional fraction and a unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*. To set a server side timeout, use the parameter [`wait_timeout`](http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_wait_timeout).
197+
198+
199+
##### `tls`
200+
201+
```
202+
Type: bool / string
203+
Valid Values: true, false, skip-verify, <name>
204+
Default: false
205+
```
206+
207+
`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`](http://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
208+
209+
210+
##### System Variables
118211

119212
All other parameters are interpreted as system variables:
120-
* `autocommit`: *"SET autocommit=`value`"*
121-
* `time_zone`: *"SET time_zone=`value`"*
122-
* `tx_isolation`: *"SET [tx_isolation](https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_tx_isolation)=`value`"*
123-
* `param`: *"SET `param`=`value`"*
213+
* `autocommit`: `"SET autocommit=<value>"`
214+
* `time_zone`: `"SET time_zone=<value>"`
215+
* [`tx_isolation`](https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_tx_isolation): `"SET tx_isolation=<value>"`
216+
* `param`: `"SET <param>=<value>"`
124217

125-
***The values must be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed!***
218+
*The values must be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed!*
126219

127220
#### Examples
128221
```
129222
user@unix(/path/to/socket)/dbname
130223
```
131224

132225
```
133-
user:password@tcp(localhost:5555)/dbname?autocommit=true
226+
root:pw@unix(/tmp/mysql.sock)/myDatabse?loc=Local
227+
```
228+
229+
```
230+
user:password@tcp(localhost:5555)/dbname?tls=skip-verify&autocommit=true
231+
```
232+
233+
TCP via IPv6:
234+
```
235+
user:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?timeout=90s
134236
```
135237

238+
TCP using default port (3306) on localhost:
136239
```
137-
user:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?tls=skip-verify&charset=utf8mb4,utf8&sys_var=withSlash%2FandAt%40
240+
user:password@tcp/dbname&charset=utf8mb4,utf8&sys_var=esc%40ped
138241
```
139242

243+
Use the default protocol (tcp) and host (localhost:3306):
140244
```
141245
user:password@/dbname
142246
```

0 commit comments

Comments
 (0)