Description
Issue description
Using tls=true
in the DSN causes the db name in the DSN to be ignored when queries are executed.
Example code
package main
import (
"database/sql"
"fmt"
"os"
_ "github.com/go-sql-driver/mysql" // import mysql driver
)
func main() {
dsn := os.Args[1] // e.g. "test:mypass@tcp(myserver)/mydb?tls=true"
db, err := sql.Open("mysql", dsn)
if err != nil {
panic(err)
}
var cipher, dbname, ignore sql.NullString
db.QueryRow("SHOW SESSION STATUS LIKE 'Ssl_cipher';").Scan(&ignore, &cipher)
err = db.QueryRow("SELECT DATABASE();").Scan(&dbname)
if err != nil {
panic(err) // no error occurs
}
fmt.Printf("Ssl_cipher = %s\n", cipher.String)
fmt.Printf("DATABASE() = %s\n", dbname.String)
}
Edit: I modified the example to verify that no error occurs, and fixed to use NullString
to handle null return value.
I've added an all-access test user to my MySQL server using:
create user 'test'@'%' identified with 'sha256_password' by 'mypass';
grant all privileges on *.* to 'test'@'%';
flush privileges;
With TLS turned off, this produces, as expected:
myapp "test:mypass@tcp(myserver)/mydb?tls=false"
Ssl_cipher =
DATABASE() = mydb
With TLS turned on, this produces, which is unexpected:
myapp "test:mypass@tcp(myserver)/mydb?tls=true"
Ssl_cipher = ECDHE-RSA-AES128-GCM-SHA256
DATABASE() =
In the latter case, I'd expect DATABASE() = mydb
. I can manually run a USE test;
statement from my sample program, but it defeats the purpose of specifying the db name in the DSN, and in a real app, I'd have to run that prior to every statement to ensure newly created connections also use this db name.
Error log
No errors logged, that I could see.
Configuration
Driver version (or git SHA):
7daee5b
Go version:
go version go1.11.1 linux/amd64
Server version:
5.7.21-21-log MySQL Community Server (GPL)
Server OS:
Red Hat Enterprise Linux Server release 6.8 (Santiago)