Startup Options Used with GTID Replication
System Variables Used with GTID Replication
The MySQL Server options and system variables described in this section are used to monitor and control Global Transaction Identifiers (GTIDs).
For additional information, see Section 18.1.3, “Replication with Global Transaction Identifiers”.
The following server startup options are used with GTID-based replication:
-
Command-Line Format --enforce-gtid-consistency[=value]System Variable (<= 5.7.5) Name enforce_gtid_consistencyVariable Scope Global Dynamic Variable No System Variable (>= 5.7.6) Name enforce_gtid_consistencyVariable Scope Global Dynamic Variable Yes Permitted Values (<= 5.7.5) Type booleanDefault falsePermitted Values (>= 5.7.6) Type enumerationDefault OFFValid Values OFFONWARNWhen enabled, the server enforces GTID consistency by allowing execution of only statements that can be safely logged using a GTID. You must set this option 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. Added in MySQL 5.7.6.
Setting
--enforce-gtid-consistencywithout a value is an alias for--enforce-gtid-consistency=ON. This impacts on the behavior of the variable, seeenforce_gtid_consistency.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 TABLE ... SELECTstatementsCREATE TEMPORARY TABLEorDROP TEMPORARY TABLEstatements inside transactionsTransactions 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.
For more information, see Section 18.1.3.4, “Restrictions on Replication with GTIDs”.
--executed-gtids-compression-periodIntroduced 5.7.5 Deprecated 5.7.6 Command-Line Format --executed-gtids-compression-period=#Permitted Values Type integerDefault 1000Min Value 0Max Value 4294967295This option is deprecated and will be removed in a future MySQL release. Use the renamed gtid_executed_compression_period to control how the gtid_executed table is compressed.
-
Command-Line Format --gtid-mode=MODESystem Variable (<= 5.7.5) Name gtid_modeVariable Scope Global Dynamic Variable No System Variable (>= 5.7.6) Name gtid_modeVariable Scope Global Dynamic Variable Yes Permitted Values (<= 5.7.5) Type enumerationDefault OFFValid Values OFFUPGRADE_STEP_1UPGRADE_STEP_2ONPermitted Values (>= 5.7.6) Type enumerationDefault OFFValid Values OFFOFF_PERMISSIVEON_PERMISSIVEONThis option specifies whether global transaction identifiers (GTIDs) are used to identify transactions. Setting this option to
--gtid-mode=ONrequires thatenforce-gtid-consistencybe set toON. Prior to MySQL 5.7.6 thegtid_modevariable which this option controls could only be set at server startup. In MySQL 5.7.6 and later thegtid_modevariable is dynamic and enables GTID based replication to be configured online. Before using this feature, see Section 18.1.5, “Changing Replication Modes on Online Servers”.Prior to MySQL 5.7.5, starting the server with
--gtid-mode=ONrequired that the server also be started with the--log-bin,--log-slave-updates, options. In versions of MySQL 5.7.5 and later this is not a requirement. See mysql.gtid_executed Table. --gtid-executed-compression-periodIntroduced 5.7.6 Command-Line Format --gtid-executed-compression-period=#Permitted Values Type integerDefault 1000Min Value 0Max Value 4294967295Compress the
mysql.gtid_executedtable each time this many transactions have taken place. A setting of 0 means that this table is not compressed. No compression of the table occurs when binary logging is enabled, therefore the option has no effect unlesslog_binisOFF.See mysql.gtid_executed Table Compression, for more information.
In MySQL version 5.7.5, this variable was added as
executed_gtids_compression_periodand in MySQL version 5.7.6 it was renamed togtid_executed_compression_period.
The following system variables are used with GTID-based replication:
-
Introduced 5.7.6 Command-Line Format --binlog-gtid-simple-recoverySystem Variable Name binlog_gtid_simple_recoveryVariable Scope Global Dynamic Variable No Permitted Values Type booleanDefault FALSEPermitted Values (>= 5.7.7) Type booleanDefault TRUEThis variable controls how binary log files are iterated during the search for GTIDs when MySQL starts or restarts. In MySQL version 5.7.5, this variable was added as
simplified_binlog_gtid_recoveryand in MySQL version 5.7.6 it was renamed tobinlog_gtid_simple_recovery.When
binlog_gtid_simple_recovery=FALSE, the method of iterating the binary log files is:To initialize
gtid_executed, binary log files are iterated from the newest file, stopping at the first binary log that has anyPrevious_gtids_log_event. All GTIDs fromPrevious_gtids_log_eventandGtid_log_eventsare read from this binary log file. This GTID set is stored internally and calledgtids_in_binlog. The value ofgtid_executedis computed as the union of this set and the GTIDs stored in themysql.gtid_executedtable.This process could take a long time if you had a large number of binary log files without GTID events, for example created when
gtid_mode=OFF.To initialize
gtid_purged, binary log files are iterated from the oldest to the newest, stopping at the first binary log that contains either aPrevious_gtids_log_eventthat is non-empty (that has at least one GTID) or that has at least oneGtid_log_event. From this binary log it readsPrevious_gtids_log_event. This GTID set is subtracted fromgtids_in_binlogand the result stored in the internal variablegtids_in_binlog_not_purged. The value ofgtid_purgedis initialized to the value ofgtid_executed, minusgtids_in_binlog_not_purged.
When
binlog_gtid_simple_recovery=TRUE, which is the default in MySQL 5.7.7 and later, the server iterates only the oldest and the newest binary log files and the values ofgtid_purgedandgtid_executedare computed based only onPrevious_gtids_log_eventorGtid_log_eventfound in these files. This ensures only two binary log files are iterated during server restart or when binary logs are being purged.NoteIf this option is enabled,
gtid_executedandgtid_purgedmay be initialized incorrectly in the following situations:The newest binary log was generated by MySQL 5.7.5 or older, and
gtid_modewasONfor some binary logs butOFFfor the newest binary log.A
SET GTID_PURGEDstatement was issued on a MySQL version prior to 5.7.7, and the binary log that was active at the time of theSET GTID_PURGEDhas not yet been purged.
If an incorrect GTID set is computed in either situation, it will remain incorrect even if the server is later restarted, regardless of the value of this option.
-
Command-Line Format --enforce-gtid-consistency[=value]System Variable (<= 5.7.5) Name enforce_gtid_consistencyVariable Scope Global Dynamic Variable No System Variable (>= 5.7.6) Name enforce_gtid_consistencyVariable Scope Global Dynamic Variable Yes Permitted Values (<= 5.7.5) Type booleanDefault falsePermitted Values (>= 5.7.6) Type enumerationDefault 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. Added in MySQL 5.7.6.
For more information on statements that can be logged using GTID based replication, see
--enforce-gtid-consistency.Prior to MySQL 5.7.6, the boolean
enforce-gtid-consistencydefaulted toOFF. To maintain compatibility with previous versions, in MySQL 5.7.6 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 versions. 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. executed_gtids_compression_periodIntroduced 5.7.5 Deprecated 5.7.6 System Variable (>= 5.7.5) Name executed_gtids_compression_periodVariable Scope Global Dynamic Variable Yes Permitted Values Type integerDefault 1000Min Value 0Max Value 4294967295This option is deprecated and will be removed in a future MySQL release. Use the renamed
gtid_executed_compression_periodto control how thegtid_executedtable is compressed.-
System Variable Name gtid_executedVariable Scope Global, Session Dynamic Variable No System Variable (>= 5.7.7) Name gtid_executedVariable Scope Global Dynamic Variable No Permitted Values Type stringWhen 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 MASTER STATUSandSHOW SLAVE 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 MASTERcauses the global value (but not the session value) of 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 MASTER.Prior to MySQL 5.7.7, this variable could also be used with session scope, where it contained a representation of the set of transactions that are written to the cache in the current session. The session scope was deprecated in MySQL 5.7.7.
gtid_executed_compression_periodIntroduced 5.7.6 System Variable (>= 5.7.6) Name gtid_executed_compression_periodVariable Scope Global Dynamic Variable Yes Permitted Values Type integerDefault 1000Min Value 0Max Value 4294967295Compress the
mysql.gtid_executedtable each time this many transactions have been processed. A setting of 0 means that this table is not compressed. Since no compression of the table occurs when using the binary log, setting the value of the variable has no effect unless binary logging is disabled.See mysql.gtid_executed Table Compression, for more information.
In MySQL version 5.7.5, this variable was added as
executed_gtids_compression_periodand in MySQL version 5.7.6 it was renamed togtid_executed_compression_period.-
System Variable (<= 5.7.5) Name gtid_modeVariable Scope Global Dynamic Variable No System Variable (>= 5.7.6) Name gtid_modeVariable Scope Global Dynamic Variable Yes Permitted Values (<= 5.7.5) Type enumerationDefault OFFValid Values OFFUPGRADE_STEP_1UPGRADE_STEP_2ONPermitted Values (>= 5.7.6) Type enumerationDefault OFFValid Values OFFOFF_PERMISSIVEON_PERMISSIVEONControls whether GTID based logging is enabled and what type of transactions the logs can contain. Prior to MySQL 5.7.6 this variable was read-only and was set using the
--gtid-modeoption only. MySQL 5.7.6 enables this variable to be set dynamically. You must have theSUPERprivilege to set this variable.enforce_gtid_consistencymust be true before you can setgtid_mode=ON. Before modifying this variable, see Section 18.1.5, “Changing Replication Modes on Online Servers”.Transactions logged in MySQL 5.7.6 and later 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
OFF_PERMISSIVEandON_PERMISSIVEmodes added in MySQL 5.7.6 permit a mix of these transaction types in the topology. The different modes are now: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.In MySQL 5.7.6 and later, 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. In MySQL 5.7.5 and earlier, the values ofgtid_purgedandgtid_executedare not persistent whilegtid_mode=OFF. Therefore, after changinggtid_modetoOFF, once all binary logs containing GTIDs are purged, the values of these variables are lost. -
System Variable Name gtid_nextVariable Scope Session Dynamic Variable Yes Permitted Values Type enumerationDefault AUTOMATICValid Values AUTOMATICANONYMOUSUUID:NUMBERThis variable is used to specify whether and how the next GTID is obtained.
gtid_nextcan take any of the following values:AUTOMATIC: Use the next automatically-generated global transaction ID.ANONYMOUS: Transactions do not have global identifiers, and are identified by file and position only.A global transaction ID in
UUID:NUMBERformat.
Exactly which of the above options are valid depends on the setting of
gtid_mode, see Section 18.1.5.1, “Replication Mode Concepts” for more information. Setting this variable has no effect ifgtid_modeisOFF.After this variable has been set to
UUID:NUMBER, and a transaction has been committed or rolled back, an explicitSET GTID_NEXTstatement must again be issued before any other statement.In MySQL 5.7.5 and later,
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. Prior to MySQL 5.7.5, when GTIDs were enabled butgtid_nextwas notAUTOMATIC,DROP TABLEdid not work correctly when used with either of these combinations of tables. (Bug #17620053)In MySQL 5.7.1, you cannot execute any of the statements
CHANGE MASTER TO,START SLAVE,STOP SLAVE,REPAIR TABLE,OPTIMIZE TABLE,ANALYZE TABLE,CHECK TABLE,CREATE SERVER,ALTER SERVER,DROP SERVER,CACHE INDEX,LOAD INDEX INTO CACHE,FLUSH, orRESETwhengtid_nextis set to any value other thanAUTOMATIC; in such cases, the statement fails with an error. Such statements are not disallowed in MySQL 5.7.2 and later. (Bug #16062608, Bug #16715809, Bug #69045) (Bug #16062608) -
System Variable Name gtid_ownedVariable Scope Global, Session Dynamic Variable No Permitted Values Type stringThis read-only variable holds a list whose contents depend on its scope. When used with session scope, the list holds all GTIDs that are owned by this client; when used with global scope, it holds a list of all GTIDs along with their owners.
-
System Variable Name gtid_purgedVariable Scope Global Dynamic Variable Yes Permitted Values Type stringThe set of all transactions that have been purged from the binary log. This is a subset of the set of transactions in
gtid_executed. The value of this variable is a GTID set, see GTID Sets for more information.When the server starts, the global value of
gtid_purgedis initialized to a set of GTIDs. Seebinlog_gtid_simple_recoveryfor more information on how binary logs are iterated to populategtid_purged. IssuingRESET MASTERcauses the value of this variable to be reset to an empty string.It is possible to update the value of this variable, but only when
gtid_executedis the empty string, and thereforegtid_purgedis the empty string. This can occur either when replication has not been started previously, or when replication was not previously using GTIDs. Prior to MySQL 5.7.6, this variable was settable only whengtid_mode=ON. In MySQL 5.7.6 and later, this variable is settable regardless of the value ofgtid_mode.If all existing binary logs were generated using MySQL 5.7.6 or later, after issuing a
SET gtid_purgedstatement,binlog_gtid_simple_recovery=TRUE(the default setting in MySQL 5.7.7 and later) can safely be used. If binary logs from MySQL 5.7.7 or earlier exist, there is a chance thatgtid_purgedmay be computed incorrectly. Seebinlog_gtid_simple_recoveryfor more information. If you are using MySQL 5.7.7 or earlier, after issuing aSET gtid_purgedstatement note down the current binary log file name, which can be checked usingSHOW MASTER STATUS. If the server is restarted before this file has been purged, then you should usebinlog_gtid_simple_recovery=FALSEto avoidgtid_purgedorgtid_executedbeing computed incorrectly. simplified_binlog_gtid_recoveryIntroduced 5.7.5 Deprecated 5.7.6 Command-Line Format --simplified-binlog-gtid-recoverySystem Variable Name simplified_binlog_gtid_recoveryVariable Scope Global Dynamic Variable No Permitted Values Type booleanDefault FALSEThis option is deprecated and will be removed in a future MySQL release. Use the renamed
binlog_gtid_simple_recoveryto control how MySQL iterates through binary log files after a crash.