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), introduced in MySQL 5.6.5.
Many of these options and variables were renamed in MySQL 5.6.9. See their descriptions in this section for more information.
For additional information, see Section 17.1.3, “Replication with Global Transaction Identifiers”.
The followup server startup options are used with GTID-based replication:
--disable-gtid-unsafe-statementsIntroduced 5.6.5 Removed 5.6.9 Command-Line Format --disable-gtid-unsafe-statements[=value]System Variable Name disable_gtid_unsafe_statementsVariable Scope Global Dynamic Variable No Permitted Values Type boolean Default falseObsolete: Replaced by
--enforce-gtid-consistencyin MySQL 5.6.9. (Bug #14775984)-
Introduced 5.6.9 Command-Line Format --enforce-gtid-consistency[=value]System Variable Name enforce_gtid_consistencyVariable Scope Global Dynamic Variable No Permitted Values Type boolean Default falseWhen enabled, this option enforces GTID consistency by allowing execution of only those statements that can be logged in a transactionally safe manner. You must enable
--enforce-gtid-consistencybefore setting--gtid-modetoON; otherwise, enabling GTID mode fails with an error. You can (and should) use this option prior to using--gtid-mode, in order to test whether the system is ready to use GTIDs.Since only transactionally safe statements can be logged when
--enforce-gtid-consistencyis enabled, it follows that the operations listed here cannot be used with this option:CREATE TABLE ... SELECTstatementsCREATE TEMPORARY TABLEstatements inside transactionsTransactions or statements that update both transactional and nontransactional tables.
Prior to MySQL 5.6.9, this option was named
--disable-gtid-unsafe-statements. (Bug #14775984)Prior to MySQL 5.6.7, using this option caused nontransactional DML on temporary tables to fail, although changes to temporary tables are not logged when using row-based binary logging. In MySQL 5.6.7 and later, nontransactional DML statements are allowed on temporary tables with
--disable-gtid-unsafe-statements(--enforce-gtid-consistencybeginning with MySQL 5.6.9) as long as all affected tables are temporary tables (Bug #14272672).Prior to MySQL 5.6.7, mysql_upgrade could not be used with a MySQL Server running with this option enabled, unless mysql_upgrade was running with
--write-binlogexplicitly disabled. (Bug #13833710, Bug #14221043) In MySQL 5.6.7 and later, it is possible but not recommended to run mysql_upgrade on a server where--gtid-mode=ON, since the MySQL system tables use theMyISAMstorage engine, which is nontransactional.In MySQL 5.6.8 and earlier, you could not use any statements affecting nontransactional tables when
--enforce-gtid-consistencywas used (the option was then called--disable-gtid-unsafe-statements). In MySQL 5.6.9 and later, this option allows single statements updating nontransactional tables. This is intended chiefly for use with programs such as mysql_install_db and mysql_upgrade. (Bug #14722659) -
Introduced 5.6.5 Command-Line Format --gtid-mode=MODESystem Variable Name gtid_modeVariable Scope Global Dynamic Variable No Permitted Values Type enumeration Default OFFValid Values OFFUPGRADE_STEP_1UPGRADE_STEP_2ONThis option specifies whether global transaction identifiers (GTIDs) are used to identify transactions. Starting the server with
--gtid-mode=ONrequires that the server also be started with the--log-bin,--log-slave-updates, and--enforce-gtid-consistencyoptions.Setting this option to
OFFwhen there are GTIDs in the binary log or in the relay log, or toONwhen there remain anonymous transactions to be executed, causes an error.ImportantThis option does not employ boolean values; its values are in fact enumerated. You should not attempt to use numeric values when setting this option, as these may lead to unexpected results. The values
UPGRADE_STEP_1andUPGRADE_STEP_2are reserved for future use, but currently are not supported in production; if you use one of these two values with--gtid-mode, the server refuses to start.The values of
gtid_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.Prior to MySQL 5.6.7, mysql_upgrade could not be used with a MySQL Server running with this option enabled, unless mysql_upgrade was running with
--write-binlogexplicitly disabled. (Bug #13833710, Bug #14221043)Prior to MySQL 5.6.10, setting the global value for the
sql_slave_skip_countervariable to 1 had no effect when--gtid-modewas set toON. (Bug #15833516) A workaround in MySQL 5.6.9 and earlier versions is to reset the slave's position usingCHANGE MASTER TO ... MASTER_LOG_FILE = ... MASTER_LOG_POS = ..., including theMASTER_AUTO_POSITION = 0option with this statement if needed.
The following system variables are used with GTID-based replication:
-
Introduced 5.6.23 Command-Line Format --binlog-gtid-simple-recoverySystem Variable Name binlog_gtid_simple_recoveryVariable Scope Global Dynamic Variable No Permitted Values Type boolean Default FALSEThis variable controls how binary log files are iterated during the search for GTIDs when MySQL starts or restarts. In MySQL version 5.6.21, this variable was added as
simplified_binlog_gtid_recoveryand in MySQL version 5.6.23 it was renamed tobinlog_gtid_simple_recovery.When
binlog_gtid_simple_recovery=FALSE, the iteration starts from the newest file to initializegtid_executed, and starts from the oldest file to initializegtid_purged. This process could take a long time if you had a large number of binary log files without GTID events, for example created whengtid_mode=OFF.When
binlog_gtid_simple_recovery=TRUE, the server does not open more than two binary logs when iterating to populategtid_purgedandgtid_executed, either 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: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.
disable_gtid_unsafe_statementsIntroduced 5.6.5 Removed 5.6.9 Command-Line Format --disable-gtid-unsafe-statements[=value]System Variable Name disable_gtid_unsafe_statementsVariable Scope Global Dynamic Variable No Permitted Values Type boolean Default falseObsolete: Replaced by
enforce_gtid_consistencyin MySQL 5.6.9. (Bug #14775984)-
Introduced 5.6.5 Removed 5.6.9 System Variable Name gtid_doneVariable Scope Global, Session Dynamic Variable No Permitted Values Type string Obsolete: replaced in MySQL 5.6.9 by
gtid_executed. (Bug #14775984) -
Introduced 5.6.9 Command-Line Format --enforce-gtid-consistency[=value]System Variable Name enforce_gtid_consistencyVariable Scope Global Dynamic Variable No Permitted Values Type boolean Default falseWhen this variable is true, the server enforces GTID consistency by allowing execution of only those statements that can be logged in a transactionally safe manner. You must enable GTID consistency (by using
--enforce-gtid-consistency) before you can start the server with--gtid-mode=ON; otherwise, enabling GTID mode fails with an error. You can (and should) enable GTID consistency prior to using--gtid-mode, in order to test whether the system is ready to use GTIDs.Since only transactionally safe statements can be logged when
enforce_gtid_consistencyis true, it follows that the operations listed here cannot be used when this is the case:CREATE TABLE ... SELECTstatementsCREATE TEMPORARY TABLEstatements inside transactionsTransactions or statements that update both transactional and nontransactional tables.
This variable is read-only. To set it, use the
--enforce-gtid-consistencyoption on the command line or in an option file when starting the MySQL Server.Prior to MySQL 5.6.9, this variable was named
disable_gtid_unsafe_statements. (Bug #14775984) -
Introduced 5.6.9 System Variable Name gtid_executedVariable Scope Global, Session Dynamic Variable No Permitted Values Type string When used with global scope, this variable contains a representation of the set of all transactions that are logged in the binary log. This is the same as the value of the
Executed_Gtid_Setcolumn in the output ofSHOW MASTER STATUSandSHOW SLAVE STATUS.When used with session scope, this variable contains a representation of the set of transactions that are written to the cache in the current session.
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.When the server starts,
@@global.gtid_executedis initialized to the union of the following two sets:The GTIDs listed in the
Previous_gtids_log_eventof the newest binary logThe GTIDs found in every
Gtid_log_eventin the newest binary log.
Thereafter, GTIDs are added to the set as transactions are executed.
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. The set is also cleared if the server is shut down and all binary logs are removed.Prior to MySQL 5.6.9, this variable was known as
gtid_done. -
Introduced 5.6.5 Removed 5.6.9 System Variable Name gtid_lostVariable Scope Global Dynamic Variable No Permitted Values Type string Obsolete: Replaced by
gtid_purgedin MySQL 5.6.9. (Bug #14775984) -
Introduced 5.6.5 System Variable Name gtid_modeVariable Scope Global Dynamic Variable No Permitted Values Type enumeration Default OFFValid Values OFFUPGRADE_STEP_1UPGRADE_STEP_2ONShows whether GTIDs are enabled. Read-only; set using
--gtid-mode. -
Introduced 5.6.5 System Variable Name gtid_nextVariable Scope Session Dynamic Variable Yes Permitted Values Type enumeration Default 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.
You must have the
SUPERprivilege to set this variable. Setting this variable has no effect ifgtid_modeisOFF.Prior to MySQL 5.6.20, when GTIDs were enabled but
gtid_nextwas notAUTOMATIC,DROP TABLEdid not work correctly 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. In MySQL 5.6.20 and later,DROP TABLEorDROP TEMPORARY TABLEfails with an explicit error when used with either of these combinations of tables. (Bug #17620053)In MySQL 5.6.11 only, 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.6.12 and later. (Bug #16062608, Bug #16715809, Bug #69045) -
Introduced 5.6.5 System Variable Name gtid_ownedVariable Scope Global, Session Dynamic Variable No Permitted Values Type string This 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.
-
Introduced 5.6.9 System Variable Name gtid_purgedVariable Scope Global Dynamic Variable Yes Permitted Values Type string The set of all transactions that have been purged from the binary log. This is a subset of the set of transactions in
gtid_executed.When the server starts, the global value of
gtid_purgedis initialized to the set of GTIDs contained by thePrevious_gtid_log_eventof the oldest binary log. When a binary log is purged,gtid_purgedis re-read from the binary log that has now become the oldest one.Prior to MySQL 5.6.9, this variable was known as
gtid_lost, and was read-only. In MySQL 5.6.9 and later, it is possible to update the value of this variable. (Bug #14797808)To update the value of this variable,
gtid_modemust beON,gtid_executedmust be the empty string, and thereforegtid_purgedwill also be the empty string. This can occur either when replication has not been started previously, or when replication was not previously using GTIDs.After executing
SET gtid_purged, you should note down the current binary log filename, 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=0(the default in 5.6) to avoidgtid_purgedorgtid_executedbeing computed incorrectly.Issuing
RESET MASTERcauses the value of this variable to be reset to an empty string. simplified_binlog_gtid_recoveryIntroduced 5.6.21 Deprecated 5.6.23 Command-Line Format --simplified-binlog-gtid-recoverySystem Variable Name simplified_binlog_gtid_recoveryVariable Scope Global Dynamic Variable No Permitted Values Type boolean Default 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.