MySQL 8.3.0
Source Code Documentation
Compression

Compression is:

  • its own protocol layer
  • transparent to the other MySQL protocol layers
  • compressing a string of bytes (which may even be a part of Protocol::Packet)

It is enabled if:

  • the server announces CLIENT_COMPRESS or CLIENT_ZSTD_COMPRESSION_ALGORITHM in its Protocol::Handshake based on variable protocol_compression_algorithms and
  • the client does following:
    • if client flags match with server flags, then client announces the matching flag as part of Protocol::HandshakeResponse: if matching flag is CLIENT_ZSTD_COMPRESSION_ALGORITHM then client sends extra 1 byte in Protocol::HandshakeResponse:
    • if client flags do not match then connection fallsback to uncompressed mode.
  • Server finishes the Connection Phase with an OK_Packet.

If both CLIENT_COMPRESS and CLIENT_ZSTD_COMPRESSION_ALGORITHM are set then zlib is used.

Compressed Packet