go-sql-driver/mysql · error
invalid bool value: {value}
Error message
invalid bool value: {value} What it means
While parsing the DSN query string, the 'allowAllFiles' key is read with readBool, which accepts only 1/true/TRUE/True/0/false/FALSE/False (utils.go:92). Any other value yields 'invalid bool value: <value>' at dsn.go:498. allowAllFiles disables the INFILE allowlist, allowing LOAD DATA LOCAL INFILE to read any file (security-sensitive).
Source
Thrown at dsn.go:498
}
// parseDSNParams parses the DSN "query string"
// Values must be url.QueryEscape'ed
func parseDSNParams(cfg *Config, params string) (err error) {
for v := range strings.SplitSeq(params, "&") {
key, value, found := strings.Cut(v, "=")
if !found {
continue
}
// cfg params
switch key {
// Disable INFILE allowlist / enable all files
case "allowAllFiles":
var isBool bool
cfg.AllowAllFiles, isBool = readBool(value)
if !isBool {
return errors.New("invalid bool value: " + value)
}
// Use cleartext authentication mode (MySQL 5.5.10+)
case "allowCleartextPasswords":
var isBool bool
cfg.AllowCleartextPasswords, isBool = readBool(value)
if !isBool {
return errors.New("invalid bool value: " + value)
}
// Allow fallback to unencrypted connection if server does not support TLS
case "allowFallbackToPlaintext":
var isBool bool
cfg.AllowFallbackToPlaintext, isBool = readBool(value)
if !isBool {
return errors.New("invalid bool value: " + value)
}
View on GitHub (pinned to c426bd9379)
Solutions
- Use one of the accepted tokens: allowAllFiles=true (or 1/True/TRUE) / allowAllFiles=false (or 0/False/FALSE).
- If the value comes from config, normalize it with a helper that maps yes/on/enable to 'true' and no/off/disable to 'false'.
- Omit the param if you want the default (false) — LOAD DATA LOCAL INFILE stays restricted.
Example fix
// before dsn := "user@tcp(host:3306)/db?allowAllFiles=yes" // after dsn := "user@tcp(host:3306)/db?allowAllFiles=true"
Defensive patterns
Strategy: validation
Validate before calling
func validMySQLBool(v string) bool {
switch v {
case "1", "true", "TRUE", "True", "0", "false", "FALSE", "False":
return true
}
return false
}
// usage: if !validMySQLBool(val) { /* reject allowAllFiles value */ } Try / catch
if _, err := mysql.ParseDSN(dsn); err != nil && strings.Contains(err.Error(), "invalid bool value") {
// normalize the offending ?allowAllFiles=... token and rebuild
} Prevention
- Remember the only accepted bool tokens are 1/true/TRUE/True/0/false/FALSE/False.
- Normalize env/config booleans to 'true'/'false' at the config boundary.
- Treat allowAllFiles as security-sensitive: prefer leaving it unset.
When it happens
Trigger: A DSN like '?allowAllFiles=yes', '?allowAllFiles=on', '?allowAllFiles=enable', or '?allowAllFiles=' (empty).
Common situations: Copying boolean conventions from another driver (postgres/yaml uses yes/no/on/off); an env var templated in as 'True' works but 'YES' does not; a trailing '=' from a config template.
Related errors
- invalid DSN: did you forget to escape a param value?
- invalid DSN: missing the slash separating the database name
- invalid DSN: interpolateParams can not be used with unsafe c
- default addr for network '{cfg.Net}' unknown
- invalid value / unknown config name: {cfg.TLSConfig}
AI-assisted analysis of go-sql-driver/mysql@c426bd9379 (2026-08-04).
Data as JSON: /data/errors/37370aa6026aa288.json.
Report an issue: GitHub.