googleapis/mcp-toolbox · error
sql.Open: %w
Error message
sql.Open: %w
What it means
sql.Open validates the driver name and DSN format without connecting. If the mysql driver is not registered or the DSN is malformed, RunSQL's pool setup fails with this error.
Source
Thrown at internal/sources/oceanbase/oceanbase.go:176
}
func initOceanBaseConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string) (*sql.DB, error) {
_, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
defer span.End()
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=true", user, pass, host, port, dbname)
if queryTimeout != "" {
timeout, err := time.ParseDuration(queryTimeout)
if err != nil {
return nil, fmt.Errorf("invalid queryTimeout %q: %w", queryTimeout, err)
}
dsn += "&readTimeout=" + timeout.String()
}
pool, err := sql.Open("mysql", dsn)
if err != nil {
return nil, fmt.Errorf("sql.Open: %w", err)
}
return pool, nil
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Check the wrapped DSN error for syntax details
- URL-escape special characters in the password (e.g. @ -> %40)
- Verify host/port values are non-empty and correctly formatted
- Ensure the go-sql-driver/mysql package is imported so the driver registers
Example fix
// before pass: p@ssw0rd # DSN: user:p@ssw0rd@tcp(...) -> invalid // after pass: "p%40ssw0rd" # URL-escaped in DSN
Defensive patterns
Strategy: validation
Validate before calling
import "net/url"
func dsnSafe(pass string) string { return url.QueryEscape(pass) } Prevention
- URL-escape special characters in password/user fields
- Verify host and port are populated before building the DSN
- Keep go-sql-driver/mysql imported so the driver registers
- Test connection pool creation in a startup smoke test
When it happens
Trigger: initOceanBaseConnectionPool calls sql.Open("mysql", dsn) and receives an error, typically because the DSN built from host/port/user/pass/dbname is malformed (e.g. special characters in password) or the mysql driver import is missing.
Common situations: Passwords containing characters that need URL escaping in the DSN; wrong host/port formatting; build-time issue where the mysql driver was not linked.
Related errors
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/bd7ebf0396646f31.
Report an issue: GitHub.