Default to No TLS when using FormatDSN
Author: celian-garciaCreated Jun 20, 2025Updated Sep 14, 2026
Hello, when I use the very convenient FormatDSN() function to initiate my DB connections:
e.g
mysqlConfig := mysql.Config{}
db, err := sql.Open("mysql", mysqlConfig.FormatDSN())If I don't set any TLSConfig in the mysql.Config structure, it is by default not setting tls=true.
So I have to explicitly set insecure skip verify to false to enable
e.g
tlsConfig := &tls.Config{
InsecureSkipVerify: false,
}
_ = mysql.RegisterTLSConfig("my-tls-config", tlsConfig)
mysqlConfig := mysql.Config{
TLSConfig: "my-tls-config"
}
db, err := sql.Open("mysql", mysqlConfig.FormatDSN())I was wondering if you couldn't benefit to put tls=true by default and have an additional explicit config field to disable TLS if desired. So that if I want to enable TLS but want to rely on defaults, I can.
Source: go-sql-driver/mysql