Skip to content

Commit 86f542b

Browse files
committed
preselect collation utf8_general_ci by default
this should avoid the DSN param &charset=UTF8 in most cases.
1 parent 73c990b commit 86f542b

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

connection.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
type mysqlConn struct {
2222
cfg *config
2323
flags clientFlag
24-
charset byte
2524
cipher []byte
2625
netConn net.Conn
2726
buf *buffer

const.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,13 @@ const (
131131
flagUnknown3
132132
flagUnknown4
133133
)
134+
135+
const (
136+
collation_ascii_general_ci byte = 11
137+
collation_utf8_general_ci byte = 33
138+
collation_utf8mb4_general_ci byte = 45
139+
collation_utf8mb4_bin byte = 46
140+
collation_latin1_general_ci byte = 48
141+
collation_binary byte = 63
142+
collation_utf8mb4_unicode_ci byte = 224
143+
)

driver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func init() {
4242
addr := env("MYSQL_TEST_ADDR", "localhost:3306")
4343
dbname := env("MYSQL_TEST_DBNAME", "gotest")
4444
netAddr = fmt.Sprintf("%s(%s)", prot, addr)
45-
dsn = fmt.Sprintf("%s:%s@%s/%s?timeout=30s&strict=true&charset=utf8", user, pass, netAddr, dbname)
45+
dsn = fmt.Sprintf("%s:%s@%s/%s?timeout=30s&strict=true", user, pass, netAddr, dbname)
4646
c, err := net.Dial(prot, addr)
4747
if err == nil {
4848
available = true

packets.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ func (mc *mysqlConn) readInitPacket() (err error) {
176176

177177
if len(data) > pos {
178178
// character set [1 byte]
179-
mc.charset = data[pos]
180-
181179
// status flags [2 bytes]
182180
// capability flags (upper 2 bytes) [2 bytes]
183181
// length of auth-plugin-data [1 byte]
@@ -252,7 +250,7 @@ func (mc *mysqlConn) writeAuthPacket() error {
252250
//data[11] = 0x00
253251

254252
// Charset [1 byte]
255-
data[12] = mc.charset
253+
data[12] = collation_utf8_general_ci
256254

257255
// SSL Connection Request Packet
258256
// http://dev.mysql.com/doc/internals/en/connection-phase.html#packet-Protocol::SSLRequest

0 commit comments

Comments
 (0)