Skip to content

Commit a6f01ea

Browse files
committed
collation: update documentation
1 parent 8636b6c commit a6f01ea

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Changes:
1515

1616
New Features:
1717

18+
- Setting the connection collation is possible with the `collation` DSN parameter. This parameter should be preferred over the `charset` parameter
1819
- Logging of critical errors is configurable with `SetLogger`
1920
- Google CloudSQL support
2021

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,9 @@ Valid Values: <name>
141141
Default: none
142142
```
143143

144-
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`).
144+
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`).
145145

146-
*Please note:*
147-
148-
Usage of the `charset` parameter is discouraged because it issues queries.
146+
Usage of the `charset` parameter is discouraged because it issues additional queries to the server.
149147
Unless you need the fallback behavior, please use `collation` instead.
150148

151149
##### `collation`
@@ -156,7 +154,7 @@ Valid Values: <name>
156154
Default: utf8_general_ci
157155
```
158156

159-
Sets the collation used for client-server interaction on connection. In contrast to `charset`, `collation` does not issue queries. If the specified collation is unavailable on the target server, the connection will fail.
157+
Sets the collation used for client-server interaction on connection. In contrast to `charset`, `collation` does not issue additional queries. If the specified collation is unavailable on the target server, the connection will fail.
160158

161159
A list of valid charsets for a server is retrievable with `SHOW COLLATION`.
162160

@@ -259,7 +257,7 @@ user:password@/dbname?strict=true&sql_notes=false
259257

260258
TCP via IPv6:
261259
```
262-
user:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?timeout=90s
260+
user:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?timeout=90s&collation=utf8mb4_unicode_ci
263261
```
264262

265263
TCP on a remote host, e.g. Amazon RDS:
@@ -311,7 +309,11 @@ Alternatively you can use the [`NullTime`](http://godoc.org/github.com/go-sql-dr
311309

312310

313311
### Unicode support
314-
Since version 1.1 Go-MySQL-Driver automatically uses the collation `utf8_general_ci` by default. Adding `&charset=utf8` (alias for `SET NAMES utf8`) to the DSN is not necessary anymore in most cases.
312+
Since version 1.1 Go-MySQL-Driver automatically uses the collation `utf8_general_ci` by default.
313+
314+
Other collations / charsets can be set using the [`collation`](#collation) DSN parameter.
315+
316+
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.
315317

316318
See http://dev.mysql.com/doc/refman/5.7/en/charset-unicode.html for more details on MySQL's Unicode support.
317319

0 commit comments

Comments
 (0)