Rechercher dans le manuel MySQL
4.2.6 Connection Compression Control
Connections to the server can use a compressed protocol that reduces the number of bytes sent over the connection. By default, connections are uncompressed, but can be compressed if the server and the client agree on the compression algorithm to use.
This section describes the available compression-control configuration parameters and the information sources available for monitoring use of compression.
Compression control applies to connections to the server by client
programs and by servers participating in master/slave replication
or Group Replication. (In the following discussion, “client
connection” is shorthand for a connection to the server
originating from any source for which compression is supported,
unless context indicates a specific connection type.) Compression
control does not apply to X Protocol connections or
connections for FEDERATED
tables.
Compressed connections originate on the client side but affect CPU load on both the client and server sides because both sides perform compression and decompression operations. Because enabling compression decreases performance, its benefits occur primarily when there is low network bandwidth, network transfer time dominates the cost of compression and decompression operations, and result sets are large.
Connection Compression Configuration
As of MySQL 8.0.18, these configuration parameters are available for controlling connection compression:
The
protocol_compression_algorithms
system variable configures which compression algorithms the server permits for incoming connections.The
--compression-algorithms
and--zstd-compression-level
command-line options configure permitted compression algorithms andzstd
compression level for these client programs: mysql, mysqladmin, mysqlbinlog, mysqlcheck, mysqldump, mysqlimport, mysqlpump, mysqlshow, mysqlslap, and mysqltest, and mysql_upgrade.The
MYSQL_OPT_COMPRESSION_ALGORITHMS
andMYSQL_OPT_ZSTD_COMPRESSION_LEVEL
options for themysql_options()
function configure permitted compression algorithms andzstd
compression level for client programs that use the MySQL C API.The
MASTER_COMPRESSION_ALGORITHMS
andMASTER_ZSTD_COMPRESSION_LEVEL
options for theCHANGE MASTER TO
statement configure permitted compression algorithms andzstd
compression level for slave servers participating in master/slave replication.The
group_replication_recovery_compression_algorithm
andgroup_replication_recovery_zstd_compression_level
system variables configure permitted compression algorithms andzstd
compression level for Group Replication recovery connections when a new member joins a group and connects to a donor.
Configuration parameters that enable specifying compression algorithms are string-valued and take a list of one or more comma-separated compression algorithm names, in any order, chosen from the following items (not case-sensitive):
zlib
: Permit connections that use thezlib
compression algorithm.zstd
: Permit connections that use thezstd
compression algorithm (zstd 1.3).uncompressed
: Permit uncompressed connections.
Because uncompressed
is an algorithm name
that may or may not be configured, it is possible to configure
MySQL not to support uncompressed
connections.
Examples:
To configure which compression algorithms the server permits for incoming connections, set the
protocol_compression_algorithms
system variable. By default, the server permits all available algorithms. To configure that setting explicitly at startup, use these lines in the servermy.cnf
file:[mysqld] protocol_compression_algorithms=zlib,zstd,uncompressed
To set and persist the
protocol_compression_algorithms
system variable to that value at runtime, use this statement:SET PERSIST
sets the value for the running MySQL instance. It also saves the value, causing it to be used for subsequent server restarts. To change the value for the running MySQL instance without saving it for subsequent restarts, use theGLOBAL
keyword rather thanPERSIST
. See Section 13.7.5.1, “SET Syntax for Variable Assignment”.To permit only incoming connections that use
zstd
compression, configure the server at startup like this:[mysqld] protocol_compression_algorithms=zstd
Or, to make the change at runtime:
To permit the mysql client to initiate
zlib
oruncompressed
connections, invoke it like this:mysql --compression-algorithms=zlib,uncompressed
To configure replication slaves to connect to the master using
zlib
orzstd
connections, with a compression level of 7 forzstd
connections, use aCHANGE MASTER TO
statement:This assumes that the
slave_compressed_protocol
system variable is disabled, for reasons described in Legacy Connection Compression Configuration.
For successful connection setup, both sides of the connection
must agree on which compression algorithm to use. The
algorithm-negotiation process attempts to use
zlib
, then zstd
, then
uncompressed
. If the two sides can find no
common algorithm, the connection attempt fails.
Because both sides must agree on the compression algorithm, and
because uncompressed
is an algorithm value
that need not be supported, fallback to an uncompressed
connection does not necessarily occur. For example, if the
server is configured to permit zstd
and a
client is configured to permit
zlib,uncompressed
, the client cannot connect
at all. In this case, no algorithm is common to both sides, so
connection attempts fail.
Configuration parameters that enable specifying the
zstd
compression level take an integer value
from 1 to 22, with larger values indicating increasing levels of
compression. The default zstd
compression
level is 3. The compression level setting has no effect on
connections that do not use zstd
compression.
A configurable zstd
compression level enables
choosing between less network traffic and higher CPU load versus
more network traffic and lower CPU load. Higher compression
levels reduce network congestion but the additional CPU load may
reduce server performance.
Prior to MySQL 8.0.18, these configuration parameters are available for controlling connection compression:
Client programs support a
--compress
command-line option to specify use of compression for the connection to the server.MySQL Shell supports compression for connections that use classic MySQL protocol. It provides a
--compress
command-line option, acompression
parameter for URI-like string and key-value pair connection specifications, and adefaultCompress
configuration option. (These are available as of MySQL Shell 8.0.14.)For programs that use the MySQL C API, enabling the
MYSQL_OPT_COMPRESS
option for themysql_options()
function specifies use of compression for the connection to the server.For master/server replication, enabling the
slave_compressed_protocol
system variable specifies use of compression for slave connections to the master.
In each case, when use of compression is specified, the
connection uses the zlib
compression
algorithm if both sides support it, with fallback to an
uncompressed connection otherwise.
As of MySQL 8.0.18, the compression parameters just described become legacy parameters, due to the additional compression parameters introduced for more control over connection compression that are described in Connection Compression Configuration. The legacy compression parameters interact with the newer parameters and their semantics change as follows:
The meaning of the legacy
--compress
option depends on whether--compression-algorithms
is specified:When
--compression-algorithms
is not specified,--compress
is equivalent to specifying a client-side algorithm set ofzlib,uncompressed
.When
--compression-algorithms
is specified,--compress
is equivalent to specifying an algorithm set ofzlib
and the full client-side algorithm set is the union ofzlib
plus the algorithms specified by--compression-algorithms
. For example, with both--compress
and--compression-algorithms=zlib,zstd
, the permitted-algorithm set iszlib
pluszlib,zstd
; that is,zlib,zstd
. With both--compress
and--compression-algorithms=zstd,uncompressed
, the permitted-algorithm set iszlib
pluszstd,uncompressed
; that is,zlib,zstd,uncompressed
.
The same type of interaction occurs between the legacy
MYSQL_OPT_COMPRESS
option and theMYSQL_OPT_COMPRESSION_ALGORITHMS
option for themysql_options()
C API function.If the
slave_compressed_protocol
system variable is enabled, it takes precedence overMASTER_COMPRESSION_ALGORITHMS
and connections to the master usezlib
compression if both master and slave support that algorithm. Ifslave_compressed_protocol
is disabled, the value ofMASTER_COMPRESSION_ALGORITHMS
applies.
The legacy compression-control parameters are deprecated as of MySQL 8.0.18 and will be removed in a future MySQL version.
The Compression
status
variable is ON
or OFF
to
indicate whether the current connection uses compression.
The mysql client \status
command displays a line that says Protocol:
Compressed
if compression is enabled for the current
connection. If that line is not present, the connection is
uncompressed.
As of 8.0.14, the MySQL Shell \status
command displays a Compression:
line that
says Disabled
or Enabled
to indicate whether the connection is compressed.
As of MySQL 8.0.18, these additional sources of information are available for monitoring connection compression:
To monitor compression in use for client connections, use the
Compression_algorithm
andCompression_level
status variables. For the current connection, their values indicate the compression algorithm and compression level, respectively.To determine which compression algorithms the server is configured to permit for incoming connections, check the
protocol_compression_algorithms
system variable.For master/slave replication connections, the configured compression algorithms and compression level are available from multiple sources:
The Performance Schema
replication_connection_configuration
table hasCOMPRESSION_ALGORITHMS
andZSTD_COMPRESSION_LEVEL
columns.The
mysql.slave_master_info
system table hasMaster_compression_algorithms
andMaster_zstd_compression_level
columns. If themaster.info
file exists, it contains lines for those values as well.
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-connection-compression-control.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.