go-sql-driver/mysql · error

invalid DSN: missing the slash separating the database name

Error message

invalid DSN: missing the slash separating the database name

What it means

Error "invalid DSN: missing the slash separating the database name" thrown in go-sql-driver/mysql.

Solutions

  1. Add the '/' separating the network address from the database name, e.g. user:pass@tcp(127.0.0.1:3306)/dbname.
  2. If you do not want a default database, still include the trailing slash: user:pass@tcp(127.0.0.1:3306)/.

Example fix

dsn := "user:pass@tcp(127.0.0.1:3306)/mydb?parseTime=true"

When it happens

Trigger: The DSN string is parsed and no '/' separating the network address part from the database name is found.

Common situations: The DSN is malformed, e.g. 'user:pass@tcp(localhost:3306)dbname' instead of 'user:pass@tcp(localhost:3306)/dbname'. Add the '/' before the database name (an empty database name still requires the slash when params follow).


AI-assisted analysis of go-sql-driver/mysql@03d76c7e07 (2026-08-07). Data as JSON: /api/errors/05d8b1fadb24b4d7. Report an issue: GitHub.

Appendix: source

Thrown at dsn.go:31

	"context"
	"crypto/rsa"
	"crypto/tls"
	"errors"
	"fmt"
	"maps"
	"math/big"
	"net"
	"net/url"
	"sort"
	"strconv"
	"strings"
	"time"
)

var (
	errInvalidDSNUnescaped       = errors.New("invalid DSN: did you forget to escape a param value?")
	errInvalidDSNAddr            = errors.New("invalid DSN: network address not terminated (missing closing brace)")
	errInvalidDSNNoSlash         = errors.New("invalid DSN: missing the slash separating the database name")
	errInvalidDSNUnsafeCollation = errors.New("invalid DSN: interpolateParams can not be used with unsafe collations")
)

// Config is a configuration parsed from a DSN string.
// If a new Config is created instead of being parsed from a DSN string,
// the NewConfig function should be used, which sets default values.
type Config struct {
	// non boolean fields

	User                 string            // Username
	Passwd               string            // Password (requires User)
	Net                  string            // Network (e.g. "tcp", "tcp6", "unix". default: "tcp")
	Addr                 string            // Address (default: "127.0.0.1:3306" for "tcp" and "/tmp/mysql.sock" for "unix")
	DBName               string            // Database name
	Params               map[string]string // Connection parameters
	ConnectionAttributes string            // Connection Attributes, comma-delimited string of user-defined "key:value" pairs
	Collation            string            // Connection collation. When set, this will be set in SET NAMES <charset> COLLATE <collation> query
	Loc                  *time.Location    // Location for time.Time values

View on GitHub (pinned to 03d76c7e07)