go-sql-driver/mysql · error
default addr for network '%s' unknown
Error message
default addr for network '%s' unknown
What it means
Error "default addr for network '%s' unknown" thrown in go-sql-driver/mysql.
Source
Thrown at dsn.go:190
func (cfg *Config) normalize() error {
if cfg.InterpolateParams && cfg.Collation != "" && unsafeCollations[cfg.Collation] {
return errInvalidDSNUnsafeCollation
}
// Set default network if empty
if cfg.Net == "" {
cfg.Net = "tcp"
}
// Set default address if empty
if cfg.Addr == "" {
switch cfg.Net {
case "tcp":
cfg.Addr = "127.0.0.1:3306"
case "unix":
cfg.Addr = "/tmp/mysql.sock"
default:
return errors.New("default addr for network '" + cfg.Net + "' unknown")
}
} else if cfg.Net == "tcp" {
cfg.Addr = ensureHavePort(cfg.Addr)
}
if cfg.TLS == nil {
switch cfg.TLSConfig {
case "false", "":
// don't set anything
case "true":
cfg.TLS = &tls.Config{}
case "skip-verify":
cfg.TLS = &tls.Config{InsecureSkipVerify: true}
case "preferred":
cfg.TLS = &tls.Config{InsecureSkipVerify: true}
cfg.AllowFallbackToPlaintext = true
default:
cfg.TLS = getTLSConfigClone(cfg.TLSConfig)View on GitHub (pinned to 03d76c7e07)
Solutions
- Provide an explicit addr in the DSN for custom network types, since only 'tcp' and 'unix' have known default addresses.
- Register a dial function for the custom network with mysql.RegisterDialContext and always specify the address.
Example fix
mysql.RegisterDialContext("myproto", func(ctx context.Context, addr string) (net.Conn, error) {
var d net.Dialer
return d.DialContext(ctx, "tcp", addr)
})
dsn := "user:pass@myproto(127.0.0.1:3306)/mydb" When it happens
Trigger: No address was given in the DSN and the configured network is neither 'tcp' nor 'unix', so the driver cannot pick a default address.
Common situations: Occurs with a custom or misspelled network value, e.g. 'net(foo)/db' without an address. Either spell the network correctly ('tcp' or 'unix') or supply an explicit address: 'user:pass@foo(addr)/db'.
AI-assisted analysis of go-sql-driver/mysql@03d76c7e07 (2026-08-07).
Data as JSON: /api/errors/09490d40646982f4.
Report an issue: GitHub.