vitessio/vitess · error

internal value %v to MySQL value error: %v

Error message

internal value %v to MySQL value error: %v

What it means

After sizing the packet, writeBinaryRow converts each non-null value with val2MySQL; when conversion fails the write packet is recycled and this wrapped error is returned to the client. It means the value cannot be encoded into the MySQL binary result-set format.

Source

Thrown at go/mysql/query.go:1217

	data, pos := c.startEphemeralPacketWithHeader(length)

	pos = writeByte(data, pos, 0x00)

	for range nullBitMapLen {
		pos = writeByte(data, pos, 0x00)
	}

	for i, val := range row {
		if val.IsNull() {
			bytePos := (i+2)/8 + 1 + PacketHeaderSize
			bitPos := (i + 2) % 8
			data[bytePos] |= 1 << uint(bitPos)
		} else {
			v, err := val2MySQL(val)
			if err != nil {
				c.recycleWritePacket()
				return fmt.Errorf("internal value %v to MySQL value error: %v", val, err)
			}
			pos += copy(data[pos:], v)
		}
	}

	return c.writeEphemeralPacket()
}

// writeBinaryRows sends the rows of a Result with binary form.
func (c *Conn) writeBinaryRows(result *sqltypes.Result) error {
	for _, row := range result.Rows {
		if err := c.writeBinaryRow(result.Fields, row); err != nil {
			return err
		}
	}
	return nil
}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Cast the offending column to a supported type in the query
  2. Verify field type metadata matches the values actually returned
  3. Fix or extend val2MySQL support if this is a vitess-side gap

Example fix

// before
SELECT payload FROM t // payload type unsupported in binary protocol
// after
SELECT CONVERT(payload, CHAR) AS payload FROM t
Defensive patterns

Strategy: try-catch

Try / catch

if err := conn.WriteBinaryRows(fields, rows); err != nil {
	if strings.Contains(err.Error(), "to MySQL value error") {
		// retry with text protocol rendering or convert the value first
	}
	return err
}

Prevention

When it happens

Trigger: Same class of inputs as the length error (386): a row value whose type is unsupported by val2MySQL during binary row encoding for a prepared statement result.

Common situations: Unsupported vitess internal types reaching the wire encoder; schema/type mismatches after migrations; passing through MySQL types vitess does not encode.

Related errors


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