The MySQL Server system variables described in this section are used to monitor and control Global Transaction Identifiers (GTIDs). For additional information, see Section 19.1.3, “Replication with Global Transaction Identifiers”.
-
Command-Line Format --binlog-gtid-simple-recovery[={OFF|ON}]System Variable binlog_gtid_simple_recoveryScope Global Dynamic No SET_VARHint AppliesNo Type Boolean Default Value ONThis variable controls how binary log files are iterated during the search for GTIDs when MySQL starts or restarts.
When
binlog_gtid_simple_recovery=TRUE(the default), the values ofgtid_executedandgtid_purgedare computed at startup based on the values ofPrevious_gtids_log_eventin the most recent and oldest binary log files. For a description of the computation, see Thegtid_purgedSystem Variable. This setting accesses only two binary log files during server restart. If all binary logs on the server were generated using MySQL 5.7.8 or later,binlog_gtid_simple_recovery=TRUEcan always safely be used.If any binary logs from MySQL 5.7.7 or older are present on the server (for example, following an upgrade of an older server to MySQL 9.0), with
binlog_gtid_simple_recovery=TRUE,gtid_executedandgtid_purgedmight be initialized incorrectly in the following two situations:The newest binary log was generated by MySQL 5.7.5 or earlier, and
gtid_modewasONfor some binary logs butOFFfor the newest binary log.A
SET @@GLOBAL.gtid_purgedstatement was issued on MySQL 5.7.7 or earlier, and the binary log that was active at the time of theSET @@GLOBAL.gtid_purgedstatement has not yet been purged.
If an incorrect GTID set is computed in either situation, it remains incorrect even if the server is later restarted with
binlog_gtid_simple_recovery=FALSE. If either of these situations apply or might apply on the server, setbinlog_gtid_simple_recovery=FALSEbefore starting or restarting the server.When
binlog_gtid_simple_recovery=FALSEis set, the method of computinggtid_executedandgtid_purgedas described in Thegtid_purgedSystem Variable is changed to iterate the binary log files as follows:Instead of using the value of
Previous_gtids_log_eventand GTID log events from the newest binary log file, the computation forgtid_executediterates from the newest binary log file, and uses the value ofPrevious_gtids_log_eventand any GTID log events from the first binary log file where it finds aPrevious_gtids_log_eventvalue. If the server's most recent binary log files do not have GTID log events, for example ifgtid_mode=ONwas used but the server was later changed togtid_mode=OFF, this process can take a long time.Instead of using the value of
Previous_gtids_log_eventfrom the oldest binary log file, the computation forgtid_purgediterates from the oldest binary log file, and uses the value ofPrevious_gtids_log_eventfrom the first binary log file where it finds either a nonemptyPrevious_gtids_log_eventvalue, or at least one GTID log event (indicating that the use of GTIDs starts at that point). If the server's older binary log files do not have GTID log events, for example ifgtid_mode=ONwas only set recently on the server, this process can take a long time.
-
Command-Line Format --enforce-gtid-consistency[=value]System Variable enforce_gtid_consistencyScope Global Dynamic Yes SET_VARHint AppliesNo Type Enumeration Default Value OFFValid Values OFFONWARNDepending on the value of this variable, the server enforces GTID consistency by allowing execution of only statements that can be safely logged using a GTID. You must set this variable to
ONbefore enabling GTID based replication.The values that
enforce_gtid_consistencycan be configured to are:OFF: all transactions are allowed to violate GTID consistency.ON: no transaction is allowed to violate GTID consistency.WARN: all transactions are allowed to violate GTID consistency, but a warning is generated in this case.
--enforce-gtid-consistencyonly takes effect if binary logging takes place for a statement. If binary logging is disabled on the server, or if statements are not written to the binary log because they are removed by a filter, GTID consistency is not checked or enforced for the statements that are not logged.Only statements that can be logged using GTID safe statements can be logged when
enforce_gtid_consistencyis set toON, so the operations listed here cannot be used with this option:CREATE TEMPORARY TABLEorDROP TEMPORARY TABLEstatements inside transactions.Transactions or statements that update both transactional and nontransactional tables. There is an exception that nontransactional DML is allowed in the same transaction or in the same statement as transactional DML, if all nontransactional tables are temporary.
CREATE TABLE ... SELECTstatements are supported for storage engines that support atomic DDL.
For more information, see Section 19.1.3.7, “Restrictions on Replication with GTIDs”.
Prior to MySQL 5.7 and in early releases in that release series, the boolean
enforce_gtid_consistencydefaulted toOFF. To maintain compatibility with these earlier releases, the enumeration defaults toOFF, and setting--enforce-gtid-consistencywithout a value is interpreted as setting the value toON. The variable also has multiple textual aliases for the values:0=OFF=FALSE,1=ON=TRUE,2=WARN. This differs from other enumeration types but maintains compatibility with the boolean type used in previous releases. These changes impact on what is returned by the variable. UsingSELECT @@ENFORCE_GTID_CONSISTENCY,SHOW VARIABLES LIKE 'ENFORCE_GTID_CONSISTENCY', andSELECT * FROM INFORMATION_SCHEMA.VARIABLES WHERE 'VARIABLE_NAME' = 'ENFORCE_GTID_CONSISTENCY', all return the textual form, not the numeric form. This is an incompatible change, since@@ENFORCE_GTID_CONSISTENCYreturns the numeric form for booleans but returns the textual form forSHOWand the Information Schema. -
System Variable gtid_executedScope Global Dynamic No SET_VARHint AppliesNo Type String Unit set of GTIDs When used with global scope, this variable contains a representation of the set of all transactions executed on the server and GTIDs that have been set by a
SETgtid_purgedstatement. This is the same as the value of theExecuted_Gtid_Setcolumn in the output ofSHOW BINARY LOG STATUSandSHOW REPLICA STATUS. The value of this variable is a GTID set, see GTID Sets for more information.When the server starts,
@@GLOBAL.gtid_executedis initialized. Seebinlog_gtid_simple_recoveryfor more information on how binary logs are iterated to populategtid_executed. GTIDs are then added to the set as transactions are executed, or if anySETgtid_purgedstatement is executed.The set of transactions that can be found in the binary logs at any given time is equal to
GTID_SUBTRACT(@@GLOBAL.gtid_executed, @@GLOBAL.gtid_purged); that is, to all transactions in the binary log that have not yet been purged.Issuing
RESET BINARY LOGS AND GTIDScauses this variable to be reset to an empty string. GTIDs are not otherwise removed from this set other than when the set is cleared due toRESET BINARY LOGS AND GTIDS. gtid_executed_compression_periodCommand-Line Format --gtid-executed-compression-period=#System Variable gtid_executed_compression_periodScope Global Dynamic Yes SET_VARHint AppliesNo Type Integer Default Value 0Minimum Value 0Maximum Value 4294967295Compress the
mysql.gtid_executedtable each time this many transactions have been processed. When binary logging is enabled on the server, this compression method is not used, and instead themysql.gtid_executedtable is compressed on each binary log rotation. When binary logging is disabled on the server, the compression thread sleeps until the specified number of transactions have been executed, then wakes up to perform compression of themysql.gtid_executedtable. Setting the value of this system variable to 0 means that the thread never wakes up, so this explicit compression method is not used. Instead, compression occurs implicitly as required.InnoDBtransactions are written to themysql.gtid_executedtable by a separate process to non-InnoDBtransactions. If the server has a mix ofInnoDBtransactions and non-InnoDBtransactions, the compression controlled by this system variable interferes with the work of this process and can slow it significantly. For this reason, from that release it is recommended that you setgtid_executed_compression_periodto 0.All transactions (regardless of storage engine) are written to the
mysql.gtid_executedtable by the same process, and thegtid_executed_compression_perioddefault value is 0.See mysql.gtid_executed Table Compression for more information.
-
Command-Line Format --gtid-mode=MODESystem Variable gtid_modeScope Global Dynamic Yes SET_VARHint AppliesNo Type Enumeration Default Value OFFValid Values OFFOFF_PERMISSIVEON_PERMISSIVEONControls whether GTID based logging is enabled and what type of transactions the logs can contain. You must have privileges sufficient to set global system variables. See Section 7.1.9.1, “System Variable Privileges”.
enforce_gtid_consistencymust be set toONbefore you can setgtid_mode=ON. Before modifying this variable, see Section 19.1.4, “Changing GTID Mode on Online Servers”.Logged transactions can be either anonymous or use GTIDs. Anonymous transactions rely on binary log file and position to identify specific transactions. GTID transactions have a unique identifier that is used to refer to transactions. The different modes are:
OFF: Both new and replicated transactions must be anonymous.OFF_PERMISSIVE: New transactions are anonymous. Replicated transactions can be either anonymous or GTID transactions.ON_PERMISSIVE: New transactions are GTID transactions. Replicated transactions can be either anonymous or GTID transactions.ON: Both new and replicated transactions must be GTID transactions.
Changes from one value to another can only be one step at a time. For example, if
gtid_modeis currently set toOFF_PERMISSIVE, it is possible to change toOFForON_PERMISSIVEbut not toON.The values of
gtid_purgedandgtid_executedare persistent regardless of the value ofgtid_mode. Therefore even after changing the value ofgtid_mode, these variables contain the correct values. -
System Variable gtid_nextScope Session Dynamic Yes SET_VARHint AppliesNo Type Enumeration Default Value AUTOMATICValid Values AUTOMATICAUTOMATIC:<TAG>ANONYMOUS<UUID>:<NUMBER><UUID>:<TAG>:<NUMBER>This variable is used to specify whether and how to otain the next GTID (see Section 19.1.3, “Replication with Global Transaction Identifiers”).
Setting the session value of this system variable is a restricted operation. The session user must have either the
REPLICATION_APPLIERprivilege (see Section 19.3.3, “Replication Privilege Checks”), or privileges sufficient to set restricted session variables (see Section 7.1.9.1, “System Variable Privileges”).gtid_nextcan take any of the following values:AUTOMATIC: Use the next automatically-generated global transaction ID.AUTOMATIC:: Use the next automatically-generated global transaction ID, with the addition of a user-specified tag, in UUID:TAGTAG:NUMBER format.The tag must match the regular expression
[a-z_][a-z0-9_]{0,7}; in other words, it must conform to the following rules:The tag must consist of 1-8 characters (inclusive).
The first character can be any letter
athroughz, or an underscore (_).Each of the remaining characters can be any of the letters
athroughz, the digits0through9, or an underscore (_).
Setting
gtid_nexton the replication source toAUTOMATIC:orTAGrequires theUUID:TAG:NUMBERTRANSACTION_GTID_TAGprivilege plus at least one of the privilegesSYSTEM_VARIABLES_ADMIN,SESSION_VARIABLES_ADMIN, orREPLICATION_APPLIER. For theREPLICATION_CHECKS_APPLIERthis privilege is also required to setgtid_nextto either of these values, in addition to theREPLICATION_APPLIERprivilege; these privileges are checked when starting the replication applier thread.ANONYMOUS: Transactions do not have global identifiers, and are identified by file and position only.A global transaction ID in either of the formats
UUID:NUMBERorUUID:TAG:NUMBER.
Exactly which of the options just listed are valid depends on the setting of
gtid_mode; see Section 19.1.4.1, “Replication Mode Concepts” for more information. Setting this variable has no effect ifgtid_modeisOFF.After this variable has been set to
orUUID:NUMBER, and a transaction has been committed or rolled back, an explicitUUID:TAG:NUMBERSET gtid_nextstatement must again be issued before any other statement.DROP TABLEorDROP TEMPORARY TABLEfails with an explicit error when used on a combination of nontemporary tables with temporary tables, or of temporary tables using transactional storage engines with temporary tables using nontransactional storage engines.For more information, see The gtid_next System Variable, as well as Section 19.1.4, “Changing GTID Mode on Online Servers”.
-
System Variable gtid_ownedScope Global, Session Dynamic No SET_VARHint AppliesNo Type String Unit set of GTIDs This read-only variable is primarily for internal use. Its contents depend on its scope.
When used with global scope,
gtid_ownedholds a list of all the GTIDs that are currently in use on the server, with the IDs of the threads that own them. This variable is mainly useful for a multi-threaded replica to check whether a transaction is already being applied on another thread. An applier thread takes ownership of a transaction's GTID all the time it is processing the transaction, so@@global.gtid_ownedshows the GTID and owner for the duration of processing. When a transaction has been committed (or rolled back), the applier thread releases ownership of the GTID.When used with session scope,
gtid_ownedholds a single GTID that is currently in use by and owned by this session. This variable is mainly useful for testing and debugging the use of GTIDs when the client has explicitly assigned a GTID for the transaction by settinggtid_next. In this case,@@session.gtid_owneddisplays the GTID all the time the client is processing the transaction, until the transaction has been committed (or rolled back). When the client has finished processing the transaction, the variable is cleared. Ifgtid_next=AUTOMATICis used for the session,gtid_ownedis populated only briefly during the execution of the commit statement for the transaction, so it cannot be observed from the session concerned, although it is listed if@@global.gtid_ownedis read at the right point. If you have a requirement to track the GTIDs that are handled by a client in a session, you can enable the session state tracker controlled by thesession_track_gtidssystem variable.
-
System Variable gtid_purgedScope Global Dynamic Yes SET_VARHint AppliesNo Type String Unit set of GTIDs The global value of the
gtid_purgedsystem variable (@@GLOBAL.gtid_purged) is a GTID set consisting of the GTIDs of all the transactions that have been committed on the server, but do not exist in any binary log file on the server.gtid_purgedis a subset ofgtid_executed. The following categories of GTIDs are ingtid_purged:GTIDs of replicated transactions that were committed with binary logging disabled on the replica.
GTIDs of transactions that were written to a binary log file that has now been purged.
GTIDs that were added explicitly to the set by the statement
SET @@GLOBAL.gtid_purged.
When the server starts, the global value of
gtid_purgedis initialized to a set of GTIDs. For information on how this GTID set is computed, see Thegtid_purgedSystem Variable. If binary logs from MySQL 5.7.7 or older are present on the server, you might need to setbinlog_gtid_simple_recovery=FALSEin the server's configuration file to produce the correct computation. See the description forbinlog_gtid_simple_recoveryfor details of the situations in which this setting is needed.You must have the
TRANSACTION_GTID_TAGto setgtid_purged.Issuing
RESET BINARY LOGS AND GTIDScauses the value ofgtid_purgedto be reset to an empty string.You can set the value of
gtid_purgedin order to record on the server that the transactions in a certain GTID set have been applied, although they do not exist in any binary log on the server. An example use case for this action is when you are restoring a backup of one or more databases on a server, but you do not have the relevant binary logs containing the transactions on the server.ImportantGTIDs are only available on a server instance up to the number of non-negative values for a signed 64-bit integer (263 - 1). If you set the value of
gtid_purgedto a number that approaches this limit, subsequent commits can cause the server to run out of GTIDs and take the action specified bybinlog_error_action. A warning message is issued when the server instance is approaching the limit.There are two ways to set the value of
gtid_purged. You can either replace the value ofgtid_purgedwith your specified GTID set, or you can append your specified GTID set to the GTID set that is already held bygtid_purged. If the server has no existing GTIDs, for example an empty server that you are provisioning with a backup of an existing database, both methods have the same result. If you are restoring a backup that overlaps the transactions that are already on the server, for example replacing a corrupted table with a partial dump from the source made using mysqldump (which includes the GTIDs of all the transactions on the server, even though the dump is partial), use the first method of replacing the value ofgtid_purged. If you are restoring a backup that is disjoint from the transactions that are already on the server, for example provisioning a multi-source replica using dumps from two different servers, use the second method of adding to the value ofgtid_purged.To replace the value of
gtid_purgedwith your specified GTID set, use the following statement:SET @@GLOBAL.gtid_purged = 'gtid_set'gtid_setmust be a superset of the current value ofgtid_purged, and must not intersect withgtid_subtract(gtid_executed,gtid_purged). In other words, the new GTID set must include any GTIDs that were already ingtid_purged, and must not include any GTIDs ingtid_executedthat have not yet been purged.gtid_setalso cannot include any GTIDs that are in@@global.gtid_owned, that is, the GTIDs for transactions that are currently being processed on the server.The result is that the global value of
gtid_purgedis set equal togtid_set, and the value ofgtid_executedbecomes the union ofgtid_setand the previous value ofgtid_executed.To append your specified GTID set to
gtid_purged, use the following statement with a plus sign (+) before the GTID set:SET @@GLOBAL.gtid_purged = '+gtid_set'gtid_setmust not intersect with the current value ofgtid_executed. In other words, the new GTID set must not include any GTIDs ingtid_executed, including transactions that are already also ingtid_purged.gtid_setalso cannot include any GTIDs that are in@@global.gtid_owned, that is, the GTIDs for transactions that are currently being processed on the server.The result is that
gtid_setis added to bothgtid_executedandgtid_purged.
If any binary logs from MySQL 5.7.7 or older are present on the
server (for example, following an upgrade of an older server to
MySQL 9.0), after issuing a SET
@@GLOBAL.gtid_purged statement, you might need to set
binlog_gtid_simple_recovery=FALSE
in the server's configuration file before restarting the server,
otherwise gtid_purged can be computed
incorrectly. See the description for
binlog_gtid_simple_recovery for details of
the situations in which this setting is needed.