{"record":{"id":"6caa65aeb686b798","repo":"go-sql-driver/mysql","slug":"invalid-dbname-q-w","errorCode":null,"errorMessage":"invalid dbname %q: %w","messagePattern":"invalid dbname %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dsn.go","lineNumber":465,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcfg.Net = dsn[j+1 : k]\n\t\t\t}\n\n\t\t\t// dbname[?param1=value1&...&paramN=valueN]\n\t\t\t// Find the first '?' in dsn[i+1:]\n\t\t\tfor j = i + 1; j < len(dsn); j++ {\n\t\t\t\tif dsn[j] == '?' {\n\t\t\t\t\tif err = parseDSNParams(cfg, dsn[j+1:]); err != nil {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdbname := dsn[i+1 : j]\n\t\t\tif cfg.DBName, err = url.PathUnescape(dbname); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid dbname %q: %w\", dbname, err)\n\t\t\t}\n\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif !foundSlash && len(dsn) > 0 {\n\t\treturn nil, errInvalidDSNNoSlash\n\t}\n\n\tif err = cfg.normalize(); err != nil {\n\t\treturn nil, err\n\t}\n\treturn\n}\n\n// parseDSNParams parses the DSN \"query string\"\n// Values must be url.QueryEscape'ed","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/03d76c7e07908e255ce62d126d07ede3f2365d86/dsn.go#L447-L483","documentation":"Thrown by ParseDSN when the database-name segment of the DSN (the text between the '/' and the first '?') fails percent-decoding via url.PathUnescape. %q is the raw dbname and %w wraps the underlying url error. It means the dbname contains a malformed percent-escape (a '%' not followed by two hex digits).","triggerScenarios":"Calling sql.Open or mysql.ParseDSN with a DSN whose database segment has a broken percent-escape, e.g. \"user@tcp(127.0.0.1:3306)/my%db\" or \".../db%GG\". url.PathUnescape rejects these because '%d'/'%GG' are not valid hex sequences.","commonSituations":"Database names containing special characters that a developer tried to percent-encode but mistyped; a literal '%' copied from another source; programmatic DSN assembly that inserts a raw '%' character.","solutions":["Read the %q value in the error to see the exact raw dbname, then remove or correct the percent-encoding (encode a literal '%' as '%25').","Avoid special characters in the database name, or build the dbname segment with proper URL encoding (e.g. url.PathEscape).","If the name genuinely contains a '%', escape it as %25 in the DSN string."],"exampleFix":"// before\ndb, err := sql.Open(\"mysql\", \"user@tcp(127.0.0.1:3306)/my%db\")\n// after (literal % encoded as %25)\ndb, err := sql.Open(\"mysql\", \"user@tcp(127.0.0.1:3306)/my%25db\")","handlingStrategy":"validation","validationCode":"// Validate the dbname portion decodes before opening.\nimport \"net/url\"\nif _, err := url.PathUnescape(dbname); err != nil {\n    return fmt.Errorf(\"bad dbname encoding: %w\", err)\n}","typeGuard":"null","tryCatchPattern":"// DSN parse failures surface from sql.Open / ParseDSN; check err immediately.\ndb, err := sql.Open(\"mysql\", dsn)\nif err != nil {\n    return fmt.Errorf(\"invalid DSN: %w\", err)\n}","preventionTips":["Never paste a raw '%' into the DSN dbname; escape it as %25.","When building DSNs programmatically, percent-escape each segment with url.PathEscape/url.QueryEscape.","Log the full DSN (minus secrets) on open failure to spot encoding mistakes."],"tags":["go","mysql","dsn","config","go-sql-driver"],"backgroundTag":null,"analyzedSha":"03d76c7e07908e255ce62d126d07ede3f2365d86","analyzedAt":"2026-08-07T10:39:17.340Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}