-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed as not planned
Closed as not planned
Copy link
Description
Issue description
I want to use dsn in golang to connect mysql8.0.
My dsn is like admin:pwd@tcp(host:3306)/mysql?allowCleartextPasswords=true&ssl-ca=/tmp/bundle.pem.
But get errInvalidDSNUnescaped error.
Example code
dsn := fmt.Sprintf("%s:%s@tcp(%s)/mysql?allowCleartextPasswords=true&ssl-ca=%s",
"rotateuser", authenticationToken, dbEndpoint, fmt.Sprintf("/tmp/%s-bundle.pem", "us-west-2"),
)
fmt.Println(dsn)
db, err := sql.Open("mysql", dsn)
Error log
panic: invalid DSN: did you forget to escape a param value?
goroutine 1 [running]:
main.GetClient()
/usr/local/src/pro/main.go:74 +0x39c
main.main()
/usr/local/src/pro/main.go:84 +0x13
exit status 2
Configuration
*Driver version (or git SHA):1.8.1
*Go version:1.21
*Server version:MySQL 8.0
*Server OS: ubuntu:22.04
bug code go-sql-driver/mysql@v1.8.1/dsn.go
// [protocol[(address)]]
// Find the first '(' in dsn[j+1:i]
for k = j + 1; k < i; k++ {
if dsn[k] == '(' {
// dsn[i-1] must be == ')' if an address is specified
if dsn[i-1] != ')' {
if strings.ContainsRune(dsn[k+1:i], ')') {
return nil, errInvalidDSNUnescaped
}
return nil, errInvalidDSNAddr
}
cfg.Addr = dsn[k+1 : i-1]
break
}
}
cfg.Net = dsn[j+1 : k]
}
Metadata
Metadata
Assignees
Labels
No labels