{"id":5161,"date":"2026-11-07T12:05:29","date_gmt":"2026-11-07T06:35:29","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/setting-up-mysql-master-slave-primary-replica-replication-with-gtid-on-ubuntu-2404\/"},"modified":"2026-11-07T12:05:29","modified_gmt":"2026-11-07T06:35:29","slug":"setting-up-mysql-master-slave-primary-replica-replication-with-gtid-on-ubuntu-2404","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/setting-up-mysql-master-slave-primary-replica-replication-with-gtid-on-ubuntu-2404\/","title":{"rendered":"Setting Up MySQL Master-Slave (Primary-Replica) Replication with GTID on Ubuntu 24.04"},"content":{"rendered":"<p style=\"font-size:17px;line-height:1.7;color:#333;margin-bottom:20px\">In mission-critical web hosting and database infrastructure, relying on legacy binary log file-and-position replication introduces severe administrative overhead, brittle failover sequences, and catastrophic replication drift. Modern enterprise Linux deployments require Global Transaction Identifiers (GTID) natively coupled with crash-safe replication appliers to achieve deterministic primary-to-replica consistency across high-throughput production clusters. While developers can test multi-node topologies in sandbox environments like <a href=\"https:\/\/cpanelfree.com\">CpanelFree<\/a>, hardening primary-replica replication on Ubuntu 24.04 LTS (Noble Numbat) demands atomic transaction boundary enforcement, multi-threaded worker pipelines, and low-latency network socket tuning.<\/p>\n<p><!-- more --><\/p>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Direct Answer: What Is MySQL GTID Replication on Ubuntu 24.04?<\/h2>\n<div class=\"wp-block-group has-background\" style=\"background:#f9f9f9;border-left:4px solid #001b41;border-radius:4px;padding:18px 22px;margin:24px 0\">\n<p style=\"margin:0;font-size:15px;line-height:1.6;color:#333\"><strong>Direct Answer:<\/strong> MySQL GTID (Global Transaction Identifier) replication on Ubuntu 24.04 pairs unique 128-bit UUID transaction tags with monotonic sequence numbers across primary and replica nodes, eliminating binary log coordinate dependencies. This architecture enables seamless failover, ensures crash-safe transaction replaying, eliminates replication drift, and simplifies multi-threaded slave pipeline synchronization.<\/p>\n<\/div>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Understanding GTID Architecture vs. Legacy Log Coordinates<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">For nearly two decades, MySQL replication depended exclusively on the tuple of a binary log filename and a byte offset (for example, <code>mysql-bin.000042:154892<\/code>). While conceptually straightforward, this legacy approach breaks down during failover orchestration. When a primary node suffers an unrecoverable failure, finding the exact transaction boundary on different replica candidates requires dissecting binary log events, correlating binlog coordinates, and running error-prone manual reconciliation scripts. A single miscalculated byte offset can trigger duplicate key insertions, missing updates, or broken replication streams.<\/p>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">Global Transaction Identifiers (GTIDs) completely redefine replication mechanics in MySQL 8.4 and 8.0 on Ubuntu 24.04. Every transaction committed on the primary instance is stamped with an immutable identifier formatted as <code>source_id:transaction_counter<\/code> (e.g., <code>3E11FA47-71CA-11E1-9E33-C80AA9429562:23<\/code>). Here, <code>source_id<\/code> is the <code>server_uuid<\/code> generated during instance initialization, while the integer represents an incremental 1-based transaction sequence. When a replica connects using GTID auto-positioning (<code>SOURCE_AUTO_POSITION = 1<\/code>), it automatically exchanges its executed GTID set (<code>gtid_executed<\/code>) with the primary. The primary then streams exclusively the delta of transactions missing from the replica\u2019s history, eliminating coordinate math completely.<\/p>\n<blockquote class=\"wp-block-quote\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:16px 20px;margin:24px 0\">\n<p><strong style=\"color:#001b41\">Architecture Note:<\/strong> Enforcing <code>enforce_gtid_consistency = ON<\/code> is strictly required in production. This setting prohibits non-deterministic statements that violate transaction atomicity\u2014such as <code>CREATE TABLE ... SELECT<\/code>, creating temporary tables inside transactions, or mixing non-transactional MyISAM tables with transactional InnoDB tables. This guarantees that all transactions can be faithfully replayed in any cluster node without divergence.<\/p>\n<\/blockquote>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Architectural Comparison: Legacy Binlog vs. Tuned GTID Replication<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">The operational contrast between legacy log coordinate replication and a properly tuned GTID implementation with multi-threaded appliers is dramatic across failover complexity, replica lag, and crash survivability:<\/p>\n<figure class=\"wp-block-table is-style-regular\">\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;font-size:15px;text-align:left\">\n<thead style=\"background:#001b41;color:#ffffff\">\n<tr>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Feature \/ Metric<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Standard \/ Default<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Tuned \/ Production<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Replication Tracking<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">File Name &amp; Byte Offset Coordinates<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Global UUID:Sequence Identifiers (GTID)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Failover Topology Realignment<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Manual log inspection &amp; position recalculation<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Autonomous Auto-Positioning (Zero-Touch)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Replica Applier Execution Model<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Single-Threaded SQL Worker (Severe Lag)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Parallel LOGICAL_CLOCK Workers (Zero Lag)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Crash Recovery Protocol<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Relay log corruption risks; manual flush<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Atomic InnoDB Relay Info Tables (relay_log_recovery)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Disk fsync &amp; Commit Strategy<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Default flush cycles; per-trx commit latency<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Binary Log Group Commit &amp; NVMe Direct I\/O<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Replication Stream Security<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Plaintext TCP Sockets (Port 3306)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Enforced TLS 1.3 with Certificate Authority Verification<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Latency \/ Overhead<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Baseline<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Optimal<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Topology Planning &amp; OS-Level Baseline on Ubuntu 24.04<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">Before deploying MySQL configuration stanzas, verify that both the primary (Source) and replica (Target) nodes are deployed on low-latency private subnets. For this reference architecture, we assume two Ubuntu 24.04 LTS nodes equipped with static IP addressing and synchronized hardware clocks via <code>systemd-timesyncd<\/code> or Chrony:<\/p>\n<ul style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px;padding-left:24px\">\n<li><strong>Primary Database Node:<\/strong> <code>10.240.0.10<\/code> (Hostname: <code>db-primary.production.lan<\/code>)<\/li>\n<li><strong>Replica Database Node:<\/strong> <code>10.240.0.20<\/code> (Hostname: <code>db-replica-01.production.lan<\/code>)<\/li>\n<li><strong>Replication User:<\/strong> <code>repl_user<\/code> authenticated over TLS<\/li>\n<li><strong>MySQL Distribution:<\/strong> Native Ubuntu 24.04 LTS package repository (MySQL 8.0.x \/ 8.4 LTS)<\/li>\n<\/ul>\n<h3 style=\"color:#001b41;font-size:20px;font-weight:600;margin-top:28px;margin-bottom:14px\">Linux Kernel &amp; Socket Tuning: \/etc\/sysctl.d\/99-mysql-replication.conf<\/h3>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">High-volume replication streams exchange thousands of transaction binlog frames per second. Default Linux network socket buffers and memory swappiness parameters will cause throughput oscillations or TCP window stalling. Place the following kernel optimizations into <code>\/etc\/sysctl.d\/99-mysql-replication.conf<\/code> and reload using <code>sysctl --system<\/code>:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/sysctl.d\/99-mysql-replication.conf\n# Kernel Virtual Memory &amp; Network Socket Optimization for Enterprise MySQL 8.x\n# Target: Ubuntu 24.04 LTS with NVMe Storage Subsystem\n\n# Minimize kernel paging of MySQL InnoDB memory buffer pool\nvm.swappiness = 1\nvm.dirty_ratio = 15\nvm.dirty_background_ratio = 5\n\n# Maximum file descriptor allocations for high-connection database servers\nfs.file-max = 2097152\n\n# Network core buffers to avoid TCP window drops under heavy binlog streaming\nnet.core.rmem_max = 16777216\nnet.core.wmem_max = 16777216\nnet.core.rmem_default = 1048576\nnet.core.wmem_default = 1048576\nnet.core.somaxconn = 4096\nnet.core.netdev_max_backlog = 10000\n\n# TCP window sizing and keepalive intervals for replication streams\nnet.ipv4.tcp_rmem = 4096 87380 16777216\nnet.ipv4.tcp_wmem = 4096 65536 16777216\nnet.ipv4.tcp_keepalive_time = 300\nnet.ipv4.tcp_keepalive_intvl = 15\nnet.ipv4.tcp_keepalive_probes = 5\nnet.ipv4.tcp_fin_timeout = 15\nnet.ipv4.tcp_tw_reuse = 1\n<\/code><\/pre>\n<h3 style=\"color:#001b41;font-size:20px;font-weight:600;margin-top:28px;margin-bottom:14px\">Systemd Service Hardening: \/etc\/systemd\/system\/mysql.service.d\/override.conf<\/h3>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">By default, systemd on Ubuntu 24.04 applies conservative resource bounds on running daemons. Create a drop-in directory and configuration to allow MySQL to access adequate file descriptors and lock memory pages:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/systemd\/system\/mysql.service.d\/override.conf\n[Service]\n# Remove default file descriptor caps\nLimitNOFILE=1048576\n\n# Allow memory locking for zero-swap enterprise performance\nLimitMEMLOCK=infinity\n\n# Prevent out-of-memory killer from terminating mysqld ahead of user workloads\nOOMScoreAdjust=-900\n\n# Ensure maximum process threads for multi-threaded parallel replication\nLimitNPROC=524288\n<\/code><\/pre>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Step 1: Configuring the Primary Node (Source)<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">On the primary database server (<code>10.240.0.10<\/code>), create an enterprise configuration drop-in file at <code>\/etc\/mysql\/mysql.conf.d\/replication-primary.cnf<\/code>. Every server participating in GTID replication must be assigned a unique numeric <code>server_id<\/code> and have binary logging enabled with ROW format.<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/mysql\/mysql.conf.d\/replication-primary.cnf\n[mysqld]\n# Networking &amp; Identification\nbind-address            = 0.0.0.0\nserver-id               = 101\nreport-host             = 10.240.0.10\nreport-port             = 3306\n\n# GTID Production Configuration\ngtid_mode               = ON\nenforce_gtid_consistency = ON\n\n# Binary Logging &amp; Durability\nlog_bin                 = \/var\/log\/mysql\/mysql-bin.log\nbinlog_format           = ROW\nbinlog_row_image        = FULL\nbinlog_expire_logs_seconds = 259200\nmax_binlog_size         = 1G\nsync_binlog             = 1\n\n# InnoDB Crash Safety Parameters\ninnodb_flush_log_at_trx_commit = 1\ninnodb_support_xa       = ON\ninnodb_flush_method     = O_DIRECT\n\n# Group Commit Tuning for High Throughput\nbinlog_group_commit_sync_delay = 100\nbinlog_group_commit_sync_no_delay_count = 10\n\n# Disable Super Read Only on Primary\nread_only               = OFF\nsuper_read_only         = OFF\n<\/code><\/pre>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">Apply the systemd unit updates and restart MySQL on the primary server:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># Reload systemd manager and restart MySQL service\nsudo systemctl daemon-reload\nsudo systemctl restart mysql\n\n# Verify GTID status and server identification\nsudo mysql -e \"SHOW GLOBAL VARIABLES LIKE 'gtid_mode';\"\nsudo mysql -e \"SHOW GLOBAL VARIABLES LIKE 'server_id';\"\n<\/code><\/pre>\n<h3 style=\"color:#001b41;font-size:20px;font-weight:600;margin-top:28px;margin-bottom:14px\">Provisioning the Dedicated TLS Replication User<\/h3>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">Never run replication using root or broad administrative accounts. Provision a dedicated replication user restricted strictly to the replica subnet and requiring an encrypted SSL\/TLS cipher suite:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>-- Execute on Primary Node (10.240.0.10)\nCREATE USER 'repl_user'@'10.240.0.%' \nIDENTIFIED WITH caching_sha2_password BY 'P@ssw0rd_Enterpr1se_GTID_2026!'\nREQUIRE SSL;\n\n-- Grant replication slave privileges\nGRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repl_user'@'10.240.0.%';\nFLUSH PRIVILEGES;\n\n-- Verify user creation and SSL cipher requirements\nSELECT user, host, plugin, ssl_type FROM mysql.user WHERE user = 'repl_user';\n<\/code><\/pre>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Step 2: Configuring the Replica Node (Target)<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">On the replica node (<code>10.240.0.20<\/code>), configure <code>\/etc\/mysql\/mysql.conf.d\/replication-replica.cnf<\/code>. The replica must have a distinct <code>server_id<\/code>, enable GTID mode, enforce read-only protection, and utilize multi-threaded appliers to prevent replication lag under heavy transactional write bursts.<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/mysql\/mysql.conf.d\/replication-replica.cnf\n[mysqld]\n# Networking &amp; Node Identification\nbind-address            = 0.0.0.0\nserver-id               = 102\nreport-host             = 10.240.0.20\nreport-port             = 3306\n\n# Enforce Read-Only to Prevent Split-Brain Writes on Replicas\nread_only               = ON\nsuper_read_only         = ON\n\n# GTID Production Configuration\ngtid_mode               = ON\nenforce_gtid_consistency = ON\n\n# Binary Logging on Replicas (Enables Chained Replication &amp; Point-in-Time Recovery)\nlog_bin                 = \/var\/log\/mysql\/mysql-bin.log\nbinlog_format           = ROW\nbinlog_row_image        = FULL\nbinlog_expire_logs_seconds = 259200\nlog_replica_updates     = ON\n\n# Crash-Safe Applier &amp; Relay Log Durability\nrelay_log               = \/var\/log\/mysql\/mysql-relay-bin.log\nrelay_log_recovery      = ON\nrelay_log_info_repository = TABLE\nmaster_info_repository  = TABLE\n\n# Multi-Threaded Applier (MTS) for Zero Replication Lag\nreplica_parallel_workers = 8\nreplica_parallel_type   = LOGICAL_CLOCK\nreplica_preserve_commit_order = ON\n\n# Checkpoint Interval for Worker Threads\nreplica_checkpoint_period = 300\nreplica_checkpoint_group  = 512\n<\/code><\/pre>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">Restart MySQL on the replica node to activate the new configuration:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># Apply sysctl and systemd overrides identically to replica\nsudo systemctl daemon-reload\nsudo systemctl restart mysql\n\n# Verify super_read_only is engaged\nsudo mysql -e \"SHOW GLOBAL VARIABLES LIKE 'super_read_only';\"\n<\/code><\/pre>\n<blockquote class=\"wp-block-quote\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:16px 20px;margin:24px 0\">\n<p><strong style=\"color:#001b41\">Production Warning:<\/strong> Always set <code>relay_log_recovery = ON<\/code> on replica nodes. In the event of an abrupt virtual machine reboot or kernel panic, uncommitted transactions in the operating system page cache may cause relay log corruption. With <code>relay_log_recovery = ON<\/code>, the replica automatically discards unapplied relay log segments and re-fetches missing transactions directly from the primary using GTID auto-positioning, completely preventing replication corruption.<\/p>\n<\/blockquote>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Step 3: Creating a Consistent Data Snapshot with Percona XtraBackup<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">To initialize the replica without locking tables on production databases, use Percona XtraBackup 8.0. XtraBackup captures non-blocking physical hot backups while capturing the exact GTID execution coordinates. Alternatively, for smaller databases, <code>mysqldump<\/code> with <code>--single-transaction<\/code> and <code>--set-gtid-purged=ON<\/code> can be employed:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># On Primary (10.240.0.10): Export consistent dataset with GTID metadata\nsudo mysqldump -u root -p \\\n  --all-databases \\\n  --master-data=2 \\\n  --single-transaction \\\n  --quick \\\n  --routines \\\n  --triggers \\\n  --events \\\n  --set-gtid-purged=ON \\\n  | gzip -c &gt; \/tmp\/primary_gtid_snapshot.sql.gz\n\n# Stream encrypted snapshot to replica node using OpenSSH\nscp \/tmp\/primary_gtid_snapshot.sql.gz sysadmin@10.240.0.20:\/tmp\/\n\n# On Replica (10.240.0.20): Decompress and restore dataset\ngunzip &lt; \/tmp\/primary_gtid_snapshot.sql.gz | sudo mysql -u root -p\n<\/code><\/pre>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">For high-concurrency production deployments handling enterprise e-commerce or SaaS databases, running primary-replica clusters requires guaranteed I\/O throughput and sub-millisecond NVMe latencies. When moving beyond development sandboxes, deploying on <a href=\"https:\/\/merahost.org\" target=\"_blank\" rel=\"noopener\">MeraHost Enterprise Cloud<\/a> gives you access to unthrottled PCIe 4.0 NVMe arrays, optimized kernel network layers, and permanent fixed renewal pricing with zero unexpected price hikes.<\/p>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Step 4: Establishing GTID Auto-Positioning Replication<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">With the snapshot restored and identical GTID sets initialized, instruct the replica node to connect to the primary. Notice that under GTID replication, you do <strong>not<\/strong> specify <code>SOURCE_LOG_FILE<\/code> or <code>SOURCE_LOG_POS<\/code>. You simply configure <code>SOURCE_AUTO_POSITION = 1<\/code>:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>-- Execute on Replica Node (10.240.0.20)\nSTOP REPLICA;\n\n-- Configure connection to primary with TLS encryption and GTID auto-positioning\nCHANGE REPLICATION SOURCE TO\n  SOURCE_HOST='10.240.0.10',\n  SOURCE_PORT=3306,\n  SOURCE_USER='repl_user',\n  SOURCE_PASSWORD='P@ssw0rd_Enterpr1se_GTID_2026!',\n  SOURCE_AUTO_POSITION = 1,\n  SOURCE_SSL = 1,\n  SOURCE_CONNECT_RETRY = 10,\n  SOURCE_RETRY_COUNT = 86400;\n\n-- Start replication threads\nSTART REPLICA;\n<\/code><\/pre>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Step 5: Verifying Replication Health &amp; Thread Telemetry<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">Execute <code>SHOW REPLICA STATUS\\G<\/code> (or <code>SHOW SLAVE STATUS\\G<\/code> in earlier distributions) on the replica node to inspect operational metrics:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>-- Inspect detailed replication status\nSHOW REPLICA STATUS\\G\n\n-- Critical Fields to Audit:\n-- Replica_IO_Running: Yes\n-- Replica_SQL_Running: Yes\n-- Auto_Position: 1\n-- Seconds_Behind_Source: 0\n-- Last_IO_Errno: 0\n-- Last_SQL_Errno: 0\n-- Executed_Gtid_Set: 3E11FA47-71CA-11E1-9E33-C80AA9429562:1-14502\n<\/code><\/pre>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">You can also query the MySQL Performance Schema directly for fine-grained multi-threaded worker telemetry:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>-- Query replication applier worker status\nSELECT \n    CHANNEL_NAME, \n    WORKER_ID, \n    THREAD_ID, \n    SERVICE_STATE, \n    LAST_APPLIED_TRANSACTION, \n    APPLYING_TRANSACTION \nFROM performance_schema.replication_applier_status_by_worker;\n<\/code><\/pre>\n<blockquote class=\"wp-block-quote\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:16px 20px;margin:24px 0\">\n<p><strong style=\"color:#001b41\">SysAdmin Operational Tip:<\/strong> Monitor <code>Seconds_Behind_Source<\/code> through Prometheus Node Exporter and mysqld_exporter. If you observe replication lag building up despite low CPU utilization on the replica, check <code>replica_parallel_workers<\/code>. If your tables lack primary keys, parallel workers will degrade into table-scan locks. Always mandate primary keys on all tables by setting <code>sql_require_primary_key = ON<\/code>.<\/p>\n<\/blockquote>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Automated Failover &amp; Topology Promotion with GTID<\/h2>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">The greatest operational payoff of GTID architecture occurs during an unplanned primary outage. In legacy replication, promoting a replica to become the new primary required logging into each surviving replica, identifying which one was furthest ahead in the binary log, manually aligning coordinates, and pointing the rest to the promoted node. This process often took 20 to 45 minutes of high-stress incident response.<\/p>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">With GTID auto-positioning, promoting a replica is instantaneous and mathematically provable. To promote <code>db-replica-01<\/code> to become the active Primary:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>-- Step 1: Disengage replication on the replica\nSTOP REPLICA;\nRESET REPLICA ALL;\n\n-- Step 2: Disable super_read_only to accept application writes\nSET GLOBAL super_read_only = OFF;\nSET GLOBAL read_only = OFF;\n\n-- Step 3: Verify the node is ready to accept application traffic\nSHOW GLOBAL VARIABLES LIKE '%read_only%';\n<\/code><\/pre>\n<p style=\"font-size:16px;line-height:1.7;color:#444;margin-bottom:18px\">When other replicas need to be repointed to this newly promoted node, simply point them using <code>CHANGE REPLICATION SOURCE TO SOURCE_HOST='10.240.0.20', SOURCE_AUTO_POSITION = 1; START REPLICA;<\/code>. Because GTID tracks every transaction globally, each node automatically synchronizes only what it needs, with zero risk of transaction duplication.<\/p>\n<h2 style=\"color:#001b41;font-size:26px;font-weight:700;margin-top:36px;margin-bottom:16px\">Frequently Asked Questions (FAQs)<\/h2>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">How do I resolve &#8216;Slave has more GTIDs than master&#8217; errors during node reconciliation?<\/summary>\n<p style=\"margin-top:10px;color:#444\">This occurs when errant transactions are executed directly on a replica node while <code>super_read_only = OFF<\/code>. To resolve this without rebuilding the replica, identify the rogue GTID by comparing <code>gtid_executed<\/code> sets. Then, inject an empty transaction on the primary with the matching GTID using <code>SET GTID_NEXT = 'uuid:seq'; BEGIN; COMMIT; SET GTID_NEXT = 'AUTOMATIC';<\/code>. This aligns transaction sets across all nodes without corrupting application data.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">Can I switch a running MySQL replication cluster from legacy coordinates to GTID without downtime?<\/summary>\n<p style=\"margin-top:10px;color:#444\">Yes. MySQL 8.x supports online GTID migration using a staged four-step progression: First, set <code>gtid_mode = OFF_PERMISSIVE<\/code> across all nodes. Second, advance to <code>gtid_mode = ON_PERMISSIVE<\/code>. Third, set <code>enforce_gtid_consistency = ON<\/code>. Finally, set <code>gtid_mode = ON<\/code> and issue <code>CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION = 1<\/code> on all replicas. Each step can be executed dynamically without restarting mysqld.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">How does replica_parallel_type = LOGICAL_CLOCK eliminate replication lag?<\/summary>\n<p style=\"margin-top:10px;color:#444\">Default MySQL replication processes incoming relay logs sequentially via a single thread, creating a bottleneck when the primary handles concurrent writes. <code>replica_parallel_type = LOGICAL_CLOCK<\/code> enables multi-threaded slave appliers by tracking which transactions were committed together in the primary&#8217;s binary log group commit phase. Transactions that did not conflict on the primary can safely be executed concurrently on the replica, scaling replay throughput linearly across CPU cores.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">What happens to MySQL GTID replication if the private network link drops?<\/summary>\n<p style=\"margin-top:10px;color:#444\">When the network link between primary and replica drops, the replica&#8217;s I\/O thread periodically attempts to reconnect based on <code>SOURCE_CONNECT_RETRY<\/code> (e.g., every 10 seconds) up to <code>SOURCE_RETRY_COUNT<\/code> (e.g., 86,400 attempts for 24 hours). The SQL thread continues applying any transactions buffered in the local relay log. Once network connectivity is restored, GTID auto-positioning resumes streaming transactions from the exact point of interruption without administrative intervention.<\/p>\n<\/details>\n<div class=\"wp-block-group has-background\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:8px;padding:32px;margin:40px 0;text-align:center\">\n<h3 style=\"color:#001b41;margin-top:0;font-size:24px;font-weight:700\">Deploy Enterprise-Grade Production Infrastructure<\/h3>\n<p style=\"color:#444;font-size:16px;line-height:1.6;max-width:680px;margin:12px auto 24px auto\">Need guaranteed performance with zero price hikes? Host mission-critical workloads on <strong style=\"color:#001b41\">MeraHost<\/strong> with pure Enterprise NVMe, LiteSpeed Web Server, and Same Renewal Price, Always (starting at \u20b999\/mo).<\/p>\n<div class=\"wp-block-buttons\" style=\"display:flex;gap:16px;justify-content:center;flex-wrap:wrap\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"https:\/\/merahost.org\" style=\"background:#001b41;color:#ffffff;font-weight:700;padding:12px 28px;border-radius:4px;text-decoration:none;display:inline-block;font-size:15px\" target=\"_blank\" rel=\"noopener\">Explore MeraHost NVMe Cloud &rarr;<\/a><\/div>\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link\" href=\"https:\/\/cpanelfree.com\" style=\"background:transparent;color:#001b41;font-weight:600;padding:12px 24px;border:2px solid #001b41;border-radius:4px;text-decoration:none;display:inline-block;font-size:15px\">Deploy Free Staging on CpanelFree<\/a><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Configure fault-tolerant MySQL GTID replication on Ubuntu 24.04. Eliminate binlog position drift with auto-failover, crash-safety, and enterprise tuning.<\/p>\n","protected":false},"author":1,"featured_media":5160,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[249],"tags":[57,250,177,87,101],"class_list":["post-5161","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database-administration","tag-almalinux","tag-database-administration","tag-databases-performance","tag-devops","tag-sysadmin"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/5161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=5161"}],"version-history":[{"count":0,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/5161\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/5160"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=5161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=5161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=5161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}