{"record":{"id":"40906c9fba7928a8","repo":"gastownhall/beads","slug":"failed-to-open-mysql-connection-w","errorCode":null,"errorMessage":"failed to open MySQL connection: %w","messagePattern":"failed to open MySQL connection: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/perf_dolt.go","lineNumber":135,"sourceCode":"\t\tuser = cfg.GetDoltServerUser()\n\t\ttls = cfg.GetDoltServerTLS()\n\t\tpassword = cfg.GetDoltServerPasswordForPort(port)\n\t}\n\n\tdsn := doltutil.ServerDSN{\n\t\tHost:     host,\n\t\tPort:     port,\n\t\tUser:     user,\n\t\tPassword: password,\n\t\tDatabase: dbName,\n\t\tTLS:      tls,\n\t}.String()\n\n\t// Measure connection time\n\tstart := time.Now()\n\tdb, err := sql.Open(\"mysql\", dsn)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open MySQL connection: %w\", err)\n\t}\n\tdefer db.Close()\n\n\t// Set connection pool settings\n\tdb.SetMaxOpenConns(5)\n\tdb.SetMaxIdleConns(2)\n\n\tctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\n\tdefer cancel()\n\tif err := db.PingContext(ctx); err != nil {\n\t\treturn fmt.Errorf(\"failed to ping server: %w\", err)\n\t}\n\tmetrics.ConnectionTime = time.Since(start).Milliseconds()\n\n\t// Run all diagnostics\n\treturn runDoltDiagnosticQueries(ctx, db, metrics)\n}\n","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/perf_dolt.go#L117-L153","documentation":"runDoltServerDiagnostics builds a MySQL DSN and calls sql.Open; a non-nil error (invalid DSN/driver problem) is wrapped with this message. Note sql.Open rarely contacts the network — most runtime failures surface at ping (error 526).","triggerScenarios":"sql.Open(\"mysql\", dsn) returns an error, typically a malformed DSN string (bad format, invalid params) or the mysql driver not being registered.","commonSituations":"Wrong host/port/password characters needing DSN escaping; config producing a DSN like 'user:pass@tcp(host:port)/db' with missing separators; driver import removed.","solutions":["Check the composed DSN in the error context for malformed format or unescaped characters (use url.QueryEscape for password/special chars)","Verify host/port/dbname values in the Dolt server config","Ensure the go-sql-driver/mysql driver is imported for side-effect registration"],"exampleFix":"// before\ndsn := fmt.Sprintf(\"root:%s@tcp(%s:%d)/%s\", pass, host, port, db) // unescaped pass with '@' breaks DSN\n// after\ndsn := fmt.Sprintf(\"root:%s@tcp(%s:%d)/%s\", url.QueryEscape(pass), host, port, db)","handlingStrategy":"validation","validationCode":"func validDSN(user, pass, host string, port int, db string) bool {\n    _, err := mysql.ParseDSN(fmt.Sprintf(\"%s:%s@tcp(%s:%d)/%s\", user, url.QueryEscape(pass), host, port, db))\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"var opErr *net.OpError\nif errors.As(err, &opErr) { log.Printf(\"DSN/network error: %v\", opErr) }","preventionTips":["Escape DSN components with url.QueryEscape","Validate DSNs with go-sql-driver's mysql.ParseDSN before use","Keep the mysql driver import for side-effect registration"],"tags":["beads","dolt","mysql","dsn"],"backgroundTag":"mysql-connection-open-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}