content_image/810834.jpg
On the client side, an X Protocol connection request can specify several parameters for compression control: 

•The compression mode. 

•The compression level (from MySQL 8.0.20). 

•The list of permitted compression algorithms in priority order (from MySQL 8.0.22). 

<img src='content_image/810834.jpg'>

The connection mode has these permitted values: 

• disabled : The connection is uncompressed. 

## Note 

Some clients or Connectors might not support a given compression-control feature. For example, specifying compression level for X Protocol connections is supported only by MySQL Shell, not by other MySQL clients or Connectors. See the documentation for specific products for details about supported features and how to use them. 

• preferred : The server and client negotiate to find a compression algorithm they both permit. If no common algorithm is available, the connection is uncompressed. This is the default mode if not specified explicitly. 

• required : Compression algorithm negotiation occurs as for preferred  mode, but if no common algorithm is available, the connection request terminates with an error. 

In addition to agreeing on a compression algorithm for each connection, the server and client can agree on a compression level from the numeric range that applies to the agreed algorithm. As the compression level for an algorithm increases, the data compression ratio increases, which reduces the network bandwidth and transfer time needed to send the message to the client. However, the effort required for data compression also increases, taking up time and CPU and memory resources on the server. Increases in the compression effort do not have a linear relationship to increases in the compression ratio. 

In MySQL 8.0.19, X Plugin always uses the library default compression level for each algorithm (3 for zstd, 0 for LZ4, and 6 for Deflate), and the client cannot negotiate this. From MySQL 8.0.20, the client can request a specific compression level during capability negotiations with the server for an X Protocol connection. 

The default compression levels used by X Plugin from MySQL 8.0.20 have been selected through performance testing as being a good trade-off between compression time and network transit time. These defaults are not necessarily the same as the library default for each algorithm. They apply if the client does not request a compression level for the algorithm. The default compression levels are initially set to 3 for zstd, 2 for LZ4, and 3 for Deflate. You can adjust these settings using the mysqlx_zstd_default_compression_level , mysqlx_lz4_default_compression_level , and mysqlx_deflate_default_compression_level  system variables. 

To prevent excessive resource consumption on the server, X Plugin sets a maximum compression level that the server permits for each algorithm. If a client requests a compression level that exceeds this setting, the server uses its maximum permitted compression level (compression level requests by a client are supported only by MySQL Shell). The maximum compression levels are initially set to 11 for zstd, 8 for LZ4, and 5 for Deflate. You can adjust these settings using the mysqlx_zstd_max_client_compression_level , mysqlx_lz4_max_client_compression_level , and mysqlx_deflate_max_client_compression_level  system variables. 

