MySQL 8.4.2
Source Code Documentation
Integer Types

The MySQL Protocol has a set of possible encodings for integers.

Protocol::FixedLengthInteger

Fixed-Length Integer Types

A fixed-length unsigned integer stores its value in a series of bytes with the least significant byte first.

The MySQL uses the following fixed-length unsigned integer variants:

See int3store() for an example.

Protocol::LengthEncodedInteger

Length-Encoded Integer Type

An integer that consumes 1, 3, 4, or 9 bytes, depending on its numeric value

To convert a number value into a length-encoded integer:

Greater or equal Lower than Stored as
0 251 1-byte integer
251 216 0xFC + 2-byte integer
216 224 0xFD + 3-byte integer
224 264 0xFE + 8-byte integer

Similarly, to convert a length-encoded integer into its numeric value check the first byte.

Warning
If the first byte of a packet is a length-encoded integer and its byte value is 0xFE, you must check the length of the packet to verify that it has enough space for a 8-byte integer. If not, it may be an EOF_Packet instead.