{"record":{"id":"eb21f2ea9584ae70","repo":"vitessio/vitess","slug":"can-t-get-charset-to-request-binlog-stream-v","errorCode":null,"errorMessage":"can't get charset to request binlog stream: %v","messagePattern":"can't get charset to request binlog stream: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/binlog/binlogplayer/binlog_player.go","lineNumber":356,"sourceCode":"\tif !ok {\n\t\treturn fmt.Errorf(\"no binlog player client factory named %v\", binlogPlayerProtocol)\n\t}\n\tblplClient := clientFactory()\n\terr = blplClient.Dial(ctx, blp.tablet)\n\tif err != nil {\n\t\terr := fmt.Errorf(\"error dialing binlog server: %v\", err)\n\t\tlog.Error(fmt.Sprint(err))\n\t\treturn err\n\t}\n\tdefer blplClient.Close()\n\n\t// Get the current charset of our connection, so we can ask the stream server\n\t// to check that they match. The streamer will also only send per-statement\n\t// charset data if that statement's charset is different from what we specify.\n\tif dbClient, ok := blp.dbClient.(*dbClientImpl); ok {\n\t\tblp.defaultCharset, err = mysql.GetCharset(dbClient.dbConn)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"can't get charset to request binlog stream: %v\", err)\n\t\t}\n\t\tlog.Info(fmt.Sprintf(\"original charset: %v\", blp.defaultCharset))\n\t\tblp.currentCharset = blp.defaultCharset\n\t\t// Restore original charset when we're done.\n\t\tdefer func() {\n\t\t\t// If the connection has been closed, there's no need to restore\n\t\t\t// this connection-specific setting.\n\t\t\tif dbClient.dbConn == nil {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlog.Info(fmt.Sprintf(\"restoring original charset %v\", blp.defaultCharset))\n\t\t\tif csErr := mysql.SetCharset(dbClient.dbConn, blp.defaultCharset); csErr != nil {\n\t\t\t\tlog.Error(fmt.Sprintf(\"can't restore original charset %v: %v\", blp.defaultCharset, csErr))\n\t\t\t}\n\t\t}()\n\t}\n\n\tvar stream BinlogTransactionStream","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/binlog/binlogplayer/binlog_player.go#L338-L374","documentation":"Thrown by applyEvents when reading the charset of the local (target) MySQL connection via mysql.GetCharset fails, so the player cannot tell the stream server which charset to check statements against. It aborts the binlog stream request before any events are applied.","triggerScenarios":"mysql.GetCharset(dbClient.dbConn) returns an error: the target DB connection is broken/closed, the underlying `SHOW VARIABLES LIKE 'character_set%'`-style query fails, or the server does not expose charset variables (unexpected MySQL flavor/version).","commonSituations":"Target vttablet's MySQL connection dropped mid-run; running against a MySQL flavor or proxy (e.g. older MariaDB, Vitess-as-target) that doesn't return the expected charset variables; connection pool recycled between Begin and this call.","solutions":["Check the target tablet's MySQL connectivity and logs — re-establish the stream if the dbConn was closed.","Verify the target MySQL version/flavor supports the charset system variables GetCharset queries.","Restart the vreplication stream so a fresh dbClient connection is created.","If targeting Vitess or a proxy, ensure charset variables are served; consider upgrading the target to a version that supports them."],"exampleFix":"// before: continue with stale/broken connection\n//   return fmt.Errorf(\"can't get charset to request binlog stream: %v\", err)\n// after: ensure connection health before streaming\n//   if err := blp.dbClient.Reconnect(); err != nil { return err }\n//   blp.defaultCharset, err = mysql.GetCharset(dbClient.dbConn)","handlingStrategy":"try-catch","validationCode":"// confirm target serves charset variables before streaming\nrows, err := db.Query(\"SHOW VARIABLES LIKE 'character_set_connection'\")\nif err != nil {\n    return fmt.Errorf(\"target does not expose charset variables: %w\", err)\n}\nrows.Close()","typeGuard":null,"tryCatchPattern":"// wrap the whole ApplyBinlogEvents call and surface charset failure distinctly\nerr := binlogplayer.ApplyBinlogEvents(ctx, blp)\nif err != nil && strings.Contains(err.Error(), \"can't get charset\") {\n    log.Error(\"target charset unavailable; check MySQL version/flavor of target\")\n    return err // restart stream for a fresh connection\n}","preventionTips":["Use a target MySQL version matching or newer than the source","Keep target vttablet MySQL connections healthy (check wait_timeout)","Verify charset system variables are present on any proxy/vitess-as-target setup"],"tags":["mysql","charset","connection","binlog-player","vreplication"],"backgroundTag":"mysql-connection-broken","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}