Thursday, March 7, 2013

GTID(GLOBAL TRANSACTION ID) FOR MYSQL 5.6 REPLICATION

Replication: Replication enables data from one MySQL database server (the master) to be replicated to one or more MySQL database servers (the slaves). Replication is asynchronous - slaves need not be connected permanently to receive updates from the master. This means that updates can occur over long-distance connections and even over temporary or intermittent connections such as a dial-up service. Depending on the configuration, you can replicate all databases, selected databases, or even selected tables within a database. 

In MySQL version 5.6 Oracle released one of the enhancement is GTID for Replication.





Early we have to set master_log_position and master_log_file in slave instead of these both,we can use this GTID for master slave replication in MySQL 5.6.



The Global Transaction IDentifier (GTID) is a unique identifier created and associated with each transaction when it is committed on the server of origin (master). This identifier is unique not only to the server on which it originated, but is unique across all servers in a given replication setup.



We need to add and enable some variables in cnf file. The gtid_mode and enforce-gtid-consistency.Starting the server with gtid_mode=ON requires that the server also be started with the log_bin and log_slave_updates options as well.



gtid_mode  : It is the main option that needs to be enabled for global transaction IDs.



enforce-gtid-consistency : It allows execution of only those statements that can be logged in a transactionally safe manner.



For master slave replication we need to enable gtid_mode basically.



Master cnf:


Slave cnf:

Now create the replication user in Master:
 
When we see the master status we see the Executed_Gtid_Set (set of all transaction logged in the binary log).
 Now do the changes in slave server but no need to give master_log_position and master_log_file anymore. Start the slave nowCheck the replication is running or not  by using slave status.
 




MASTER_AUTO_POSITION = 1 is used when the slave attempts to connect to the master using the GTID-based replication protocol. In this case, the coordinates represented by MASTER_LOG_FILE and MASTER_LOG_POS are not used, and global transaction identifiers are used instead. Thus the use of either or both of these options together with MASTER_AUTO_POSITION causes an error.

gtid_mode must also be enabled before issuing CHANGE MASTER TO ... MASTER_AUTO_POSITION = 1. Otherwise, the statement fails with an error.

Retrieved_Gtid_set : It displays the transaction that we read from master.
Executed_Gtid_set : It displays the transaction that we already executed.




Now we check the replication is works fine if the command executed in master that is replicate on slave or not.
In Master: Check it in Slave: Got successfully replicated by GTID.

So here after no need to worry about log file and position in slave while doing change master to statement. 
    

 

No comments:

Post a Comment