go-sql-driver/mysql · critical

strict mode has been removed. See https://github.com/go-sql-

Error message

strict mode has been removed. See https://github.com/go-sql-driver/mysql/wiki/strict-mode

What it means

This is NOT a returned error — the `strict` DSN case at dsn.go:638 calls panic(). Strict mode (which turned MySQL warnings into Go errors) was removed from the driver years ago; retaining the parameter would silently mislead users, so the driver deliberately panics to surface the incompatibility. The message links the migration wiki.

Source

Thrown at dsn.go:638

		// Reject read-only connections
		case "rejectReadOnly":
			var isBool bool
			cfg.RejectReadOnly, isBool = readBool(value)
			if !isBool {
				return errors.New("invalid bool value: " + value)
			}

		// Server public key
		case "serverPubKey":
			name, err := url.QueryUnescape(value)
			if err != nil {
				return fmt.Errorf("invalid value for server pub key name: %v", err)
			}
			cfg.ServerPubKey = name

		// Strict mode
		case "strict":
			panic("strict mode has been removed. See https://github.com/go-sql-driver/mysql/wiki/strict-mode")

		// Dial Timeout
		case "timeout":
			cfg.Timeout, err = time.ParseDuration(value)
			if err != nil {
				return
			}

		// TLS-Encryption
		case "tls":
			boolValue, isBool := readBool(value)
			if isBool {
				if boolValue {
					cfg.TLSConfig = "true"
				} else {
					cfg.TLSConfig = "false"
				}
			} else if vl := strings.ToLower(value); vl == "skip-verify" || vl == "preferred" {

View on GitHub (pinned to c426bd9379)

Solutions

  1. Remove `strict=true` from the DSN entirely — the parameter no longer exists.
  2. Handle data truncation/warnings in application code by checking errors returned from Exec/Query, or set sql_mode on the MySQL server (e.g. STRICT_TRANS_TABLES) to make the server reject bad data.
  3. If you depended on strict behavior, validate inputs in Go before sending them to the database.

Example fix

// before
sql.Open("mysql", "u:p@tcp(127.0.0.1:3306)/db?strict=true")
// after
sql.Open("mysql", "u:p@tcp(127.0.0.1:3306)/db")
Defensive patterns

Strategy: validation

Validate before calling

dsn := strings.ReplaceAll(dsn, "strict=true&", "")
dsn = strings.ReplaceAll(dsn, "strict=true", "")
dsn = strings.ReplaceAll(dsn, "&strict=false", "")
dsn = strings.ReplaceAll(dsn, "strict=false", "")

Try / catch

if r := recover(); r != nil {
    if msg, _ := r.(string); strings.Contains(msg, "strict mode") {
        // strip strict= and retry DSN parse
    }
}

Prevention

When it happens

Trigger: Any DSN containing `strict=true` (or `strict=false`) parsed via ParseDSN/FormatDSN/DSN parsing path of sql.Open. The handler unconditionally panics; there is no valid value for `strict`.

Common situations: Upgrading the go-sql-driver/mysql dependency in a project whose DSN was written against an old (pre-removal) version of the driver; copy-pasting a DSN from an outdated tutorial or Stack Overflow answer.

Related errors


AI-assisted analysis of go-sql-driver/mysql@c426bd9379 (2026-08-04). Data as JSON: /data/errors/3f5dd2ff43a6afd5.json. Report an issue: GitHub.