GTID (Global Transaction Identifier) is a critical feature for managing replication in MySQL. Here's how to configure it effectively:
1. Enabling GTID Mode
- Step 1: Ensure your MySQL version supports GTID (5.6+).
- Step 2: Modify the configuration file (
my.cnf
ormy.ini
):[mysqld] gtid_mode=ON enforce_gtid_consistency=ON
- Step 3: Restart the MySQL server to apply changes.
2. Verifying GTID Status
Run the following command in MySQL CLI:
SHOW VARIABLES LIKE 'gtid%';
- Output includes
gtid_mode
andgtid_next
parameters.
3. Replication Setup with GTID
- Master: Use
binlog_format=ROW
andlog_slave_updates=ON
. - Slave: Set
server_id
and ensureauto_position
is enabled.
Example:CHANGE MASTER TO MASTER_AUTO_POSITION=1; START SLAVE;
4. Best Practices
- Always test configurations in a staging environment.
- Use MySQL official documentation for advanced troubleshooting.
- Monitor replication lag with
SHOW SLAVE STATUS\G
.
For deeper insights, check our MySQL GTID troubleshooting guide. 📚