Global Transactions Identifiers are one of the new features regarding replication in MySQL 5.6. They open up a lot of opportunities to make the life of DBAs much easier when having to maintain servers under a specific replication topology. However you should keep in mind some limitations of the current implementation. This post is the first one of a series of articles focused on the implications of enabling GTIDs on a production setup.
The manual describes very nicely how to switch to GTID-based replication, I won’t repeat it. Basically the steps are:
| 已有1人翻译此段 |
This procedure will switch all your servers from regular replication to GTID replication. But if you are running a production system, you will probably want to gradually enable GTID replication for an easier rollback in the event of a problem. And some items in the documentation are not so clear. For instance:
To find an answer to these questions, let’s create a simple replication configuration with one master and two slaves, all running MySQL 5.6 with GTIDs disabled. | 已有1人翻译此段 |
First try: configure only one of the servers with GTIDsLet’s stop slave #2, change configuration and restart it:
So unfortunately if you want replication to work correctly, gtid_mode must be ON on all servers or OFF on all servers, but not something in the middle. What if we try to reconfigure the master? This time, replication on slave #1 will stop:
These simple tests answer the first two questions: replication works only if all servers have the same value for gtid_mode, so you should restart them at the same time, which is best done by making the master read-only. However, “at the same time” means “at the same binlog position”, so you can perfectly restart the servers one by one. | 已有1人翻译此段 |
Second try: GTIDs enabled, mixing regular replication and GTID replicationThis time, we will enable GTID replication on slave #1, but not on slave #2:
ExecutingSHOW TABLES FROM teston both slaves shows that the table has been created everywhere. So once GTIDs are enabled on all servers, you can have some slaves using file-based positioning and some other slaves using GTID-based positioning. This answers the second question: we can have different replication modes on different servers, but only if all servers have gtid_mode set to ON. Could it be interesting to run file-based replication when gtid_mode is ON? I can’t think of any use case, so in practice, you’ll probably use either file-based replication only (gtid_mode=off for all servers) or GTID-based replication only (gtid_mode=on for all servers). | 已有1人翻译此段 |
Additional question: how can you know if a slave is using GTID-based replication by inspecting the output ofSHOW SLAVE STATUS? Look at the last field,Auto_Position:
ConclusionEnabling GTID-based replication can be tricky if your application does not easily tolerate downtime or read-only mode, especially if you have a lot of servers to reconfigure. It would be really nice to be able to mix servers where gtid_mode is ON with servers where gtid_mode is OFF. This would greatly simplify the transition to GTID-based replication and allow easier rollbacks if something goes wrong. |