vitessio/vitess · error
no port variable in mysql
Error message
no port variable in mysql
What it means
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.
Source
Thrown at go/vt/mysqlctl/replication.go:762
// We can not use the connection pool here. This check runs very early
// during MySQL startup when we still might be loading things like grants.
// This means we need to use an isolated connection to avoid poisoning the
// DBA connection pool for further queries.
params, err := mysqld.dbcfgs.DbaConnector().MysqlParams()
if err != nil {
return 0, err
}
conn, err := mysql.Connect(ctx, params)
if err != nil {
return 0, err
}
defer conn.Close()
qr, err := conn.ExecuteFetch("SHOW VARIABLES LIKE 'port'", 1, false)
if err != nil {
return 0, err
}
if len(qr.Rows) != 1 {
return 0, errors.New("no port variable in mysql")
}
utemp, err := qr.Rows[0][1].ToCastUint64()
if err != nil {
return 0, err
}
return int32(utemp), nil
}
// GetServerUUID returns mysql server uuid
func (mysqld *Mysqld) GetServerUUID(ctx context.Context) (string, error) {
conn, err := getPoolReconnect(ctx, mysqld.dbaPool)
if err != nil {
return "", err
}
defer conn.Recycle()
return conn.Conn.GetServerUUID()
}View on GitHub (pinned to 01a25a7d17)
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.
Defensive patterns
Strategy: fallback
Try / catch
port, err := mysqld.GetMysqlPort(ctx)
if err != nil {
if strings.Contains(err.Error(), "no port variable") {
port = portFromConfig // read from my.cnf / tablet config instead
} else {
return vterrors.Wrapf(err, "getting mysql port")
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- no read_only variable in mysql
- can't get charset to check binlog stream: %v
- can't get charset to request binlog stream: %v
- failed query BEGIN, err: %s
- error in connecting to mysql db with connection %v, err %v
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/0df2ccc29a490c9b.
Report an issue: GitHub.