{"record":{"id":"0df2ccc29a490c9b","repo":"vitessio/vitess","slug":"no-port-variable-in-mysql","errorCode":null,"errorMessage":"no port variable in mysql","messagePattern":"no port variable in mysql","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/replication.go","lineNumber":762,"sourceCode":"\t// We can not use the connection pool here. This check runs very early\n\t// during MySQL startup when we still might be loading things like grants.\n\t// This means we need to use an isolated connection to avoid poisoning the\n\t// DBA connection pool for further queries.\n\tparams, err := mysqld.dbcfgs.DbaConnector().MysqlParams()\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tconn, err := mysql.Connect(ctx, params)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tdefer conn.Close()\n\tqr, err := conn.ExecuteFetch(\"SHOW VARIABLES LIKE 'port'\", 1, false)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tif len(qr.Rows) != 1 {\n\t\treturn 0, errors.New(\"no port variable in mysql\")\n\t}\n\tutemp, err := qr.Rows[0][1].ToCastUint64()\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn int32(utemp), nil\n}\n\n// GetServerUUID returns mysql server uuid\nfunc (mysqld *Mysqld) GetServerUUID(ctx context.Context) (string, error) {\n\tconn, err := getPoolReconnect(ctx, mysqld.dbaPool)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer conn.Recycle()\n\n\treturn conn.Conn.GetServerUUID()\n}","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/replication.go#L744-L780","documentation":"GetMysqlPort runs \"SHOW VARIABLES LIKE 'port'\" and expects exactly one row. If MySQL returns zero rows (or unexpectedly more), it concludes the port variable is absent and returns this error. This typically means mysqld is not reachable/running or is an embedded/nonstandard build without a port variable.","triggerScenarios":"Calling Mysqld.GetMysqlPort when SHOW VARIABLES LIKE 'port' returns len(qr.Rows) != 1 — most commonly because the mysqld process is down so the query fails to return the expected single row, or a sandboxed/embedded MySQL has no port variable.","commonSituations":"Querying the port before mysqld has fully started during tablet init; connecting to a mysqld configured with skip-networking where the port variable context differs; tests against a stubbed mysqlctld.","solutions":["Verify mysqld is running and accepting connections (mysqladmin ping / check the socket) before calling GetMysqlPort.","Read the port from the tablet's my.cnf / Vitess config (e.g. mysqlctl's config files) as a fallback instead of querying the server.","Retry after a short delay if the call happens during mysqld startup."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"port, err := mysqld.GetMysqlPort(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"no port variable\") {\n        port = portFromConfig // read from my.cnf / tablet config instead\n    } else {\n        return vterrors.Wrapf(err, \"getting mysql port\")\n    }\n}","preventionTips":["Confirm mysqld is up (mysqladmin ping) before querying server variables.","Keep the port in Vitess's own config (my.cnf / tablet params) as the authoritative source.","Retry variable lookups during startup with assert.Eventually-style bounded polling."],"tags":["mysql","connection","port","mysqlctl"],"backgroundTag":"mysql-server-unreachable","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}