Skip to content

Default to No TLS when using FormatDSN #1728

Open

Description

@celian-garcia

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.

Activity

  1. methane commented on Sep 10, 2026

    @methane
    Member

    Hello, when I use the very convenient FormatDSN() function to initiate my DB connections: e.g

    A DSN cannot represent all the information in a Config, nor is round-trip conversion guaranteed.
    Please use sql.OpenDB(mysql.NewConnector(cfg)) instead of sql.Open("mysql", cfg.FormatDSN()).

  2. celian-garcia commented on Sep 14, 2026

    @celian-garcia
    Author

    Oh okay thanks! I didn't know that option. Every doc I checked was mentioning DSN.

    So it means I don't even have to do the TLS Config registration. I can simplify my code drastically

      mysqlConfig := mysql.Config{}
      connector, err := mysql.NewConnector(&mysqlConfig) // Will use SkipVerify false by default by design
      db := sql.OpenDB(connector)

    I will try this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions