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

  1. Verify mysqld is running and accepting connections (mysqladmin ping / check the socket) before calling GetMysqlPort.
  2. 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.
  3. 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

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


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/0df2ccc29a490c9b. Report an issue: GitHub.