DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
VGSources
Blog

How to Set Up MySQL Replication Between Two Servers (MySQL 8.4)

A practical MySQL 8.4 runbook for configuring a source and replica with GTID auto-positioning, seeding existing data, validating replication, and fixing the most common startup failures.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a new two-server deployment, use one MySQL source and one replica with GTID-based, asynchronous replication. Enable binary logging and unique server identities, seed the replica from a consistent snapshot, enable gtid_mode=ON and enforce_gtid_consistency=ON on both servers, then configure the replica with SOURCE_AUTO_POSITION=1. Start the replica and verify both replication threads before allowing normal traffic.

Replication is normally one-way: transactions committed on the source are written to its binary log, transferred to the replica, and applied there. It is asynchronous by default, so a successful write on the source can briefly exist on the source before the replica has received and executed it. That behavior affects failover, backup design, and how much data could be lost if the source fails.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What MySQL replication does

MySQL replication copies data from one database server, called the source, to one or more servers called replicas. In the common two-server arrangement, applications write to the source. The replica receives the source’s binary-log events and applies them in order. The default mode is asynchronous: the source does not wait for the replica to confirm that each transaction has been applied.

The arrangement is not automatically bidirectional. A replica should not accept independent writes to the same tables while it is applying the source’s changes. If both servers are allowed to write, conflicts and divergent data can result. Treat the source as the writer and the replica as a read-only copy unless you have designed a separate multi-source or multi-primary architecture.

Replication is also not a backup by itself. An accidental DROP TABLE, an application bug, or a malicious change can be copied to the replica. Keep independent backups and test restoring them. A replica can help with backup workflows and reporting, but it does not replace a recovery plan.

Choose GTID or file-position replication

MySQL 8.4 supports both approaches. For a new topology, GTIDs are usually the clearer choice because the replica asks for transactions by global transaction identifier instead of requiring you to maintain binary-log file names and byte positions. File-position replication remains useful when integrating with an older installation, a tool that expects coordinates, or an environment where GTIDs cannot yet be enabled.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision point GTID-based replication File-position replication
How the replica finds missing transactions Negotiates missing GTIDs automatically with SOURCE_AUTO_POSITION=1. Uses an exact source log file and position recorded for the snapshot.
Best fit New MySQL 8.4 deployments and operations where simpler provisioning and failover matter. Legacy or compatibility cases, or servers that cannot yet run with GTIDs.
Bootstrap requirement Both servers must use gtid_mode=ON and enforce_gtid_consistency=ON; the seed must carry the appropriate GTID state or history. The dump or snapshot and the recorded file/position must represent exactly the same point in time.
Main operational risk The source may purge binary-log history before the replica has retrieved the required GTIDs. Incorrect, stale, or mismatched coordinates make the replica start at the wrong point.

Your choice should also account for whether the servers already contain data, whether a maintenance window is available, whether GTIDs are already enabled, how long binary logs are retained, and whether operational simplicity outweighs compatibility with an existing procedure.

Prerequisites and topology

Before changing configuration, document which host is the source and which is the replica. Give each server a distinct MySQL server identity. The source must have binary logging enabled. A replica using GTIDs does not strictly need to write its own binary log, but disabling replica logging removes options for later failover, chaining, or making that server a new source.

  • Use supported, compatible MySQL versions; this guide targets MySQL 8.4.
  • Ensure the replica can reach the source over TCP on the MySQL port, normally 3306, using the source’s DNS name or address.
  • Permit the connection through host firewalls and network security groups without exposing MySQL more broadly than necessary.
  • Create a dedicated replication account with only the privileges required by your security policy. Do not reuse an application administrator account.
  • Decide where binary logs and relay logs will be retained, and monitor disk space.
  • Choose how the initial data will be copied: a consistent logical dump, a raw storage snapshot, or a backup product suited to large InnoDB datasets.
  • Keep independent backups even after replication is running.

A simple topology has one write endpoint pointing to the source and a separate read or reporting endpoint pointing to the replica. Do not direct writes to both hosts unless you have implemented a design intended for that behavior.

Prepare the source and replica

Give the servers unique identities

Set a different server_id on each MySQL instance. The values only need to be unique within the replication environment; use a documented numbering scheme rather than copying an identity from a cloned machine. Restart MySQL when your deployment method requires it, then verify the values with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
SHOW VARIABLES LIKE 'server_id';

Enable source binary logging

The source must write a binary log. In the source configuration, enable log_bin and choose a durable log location appropriate for your operating system. Confirm the setting after restart:

SHOW VARIABLES LIKE 'log_bin';

Binary-log retention must cover the longest period in which a replica might be offline. Retention that is too short causes a replica to request transactions that no longer exist on the source.

Create a restricted replication account

Create the account on the source and permit it to connect only from the replica’s address or an appropriately narrow host pattern. Store the password in a secret manager or protected configuration, not in a script checked into source control. The connection statement shown later uses a placeholder rather than a real credential.

If the servers communicate across an untrusted network, configure an encrypted replication connection and verify certificate and hostname validation according to your security policy. Encryption protects credentials and replicated data in transit; it does not correct an incorrectly seeded replica or a broken replication channel.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Seed the replica from a consistent point

The replica cannot begin with an arbitrary copy of the source’s files. Its initial data must represent one consistent point, and the replication method must know what transaction history follows that point.

Logical dump

A consistent logical dump is practical for many databases. For InnoDB tables, take the dump with a transaction-consistent option and include source metadata so the point used for replication is recorded. In MySQL 8.4, a typical pattern is:

mysqldump --all-databases --single-transaction --source-data=2 > seed.sql

Review the generated file before loading it. The metadata records the source coordinates or GTID context needed by the selected setup. Transfer the file securely, initialize the replica with the same compatible schema and settings, and load it there:

mysql < seed.sql

For a large InnoDB dataset, a raw consistent snapshot or MySQL Enterprise Backup can reduce the time spent exporting and importing. Whichever method you choose, preserve the transaction history or coordinates that correspond exactly to the snapshot. A snapshot without that continuation information is not a complete replication bootstrap.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Existing servers and a cold start

If both servers already contain data, stop application writes or put the source into a controlled read-only state while you bring the replica to a known point. Allow the replica to catch up before changing GTID settings. The purpose is to avoid enabling GTIDs while the two servers represent different histories.

For a fresh deployment, configure GTIDs before loading application data. For an existing deployment, schedule a maintenance window, synchronize the servers, and take a new usable backup after the GTID transition. MySQL warns that binary logs containing transactions without GTIDs cannot be used after GTIDs are enabled, so an older backup may not be suitable for provisioning a new replica.

Configure a new GTID-based replica

Enable GTIDs on both servers

Set these options in the MySQL configuration of both the source and the replica:

gtid_mode=ON
enforce_gtid_consistency=ON

Restart each server according to your operating procedure. On an existing installation, follow the required transition sequence for your version rather than switching settings while incompatible transactions are still being generated. Keep the replica’s automatic replication startup suppressed during the change so you can configure its channel deliberately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After restart, verify both variables on each host:

SHOW VARIABLES LIKE 'gtid_mode';
SHOW VARIABLES LIKE 'enforce_gtid_consistency';

Both values must be enabled before using GTID auto-positioning. If they do not match, stop and correct the configuration instead of attempting to start the channel.

Configure the source connection on the replica

With replication threads stopped, run CHANGE REPLICATION SOURCE TO on the replica. Replace the host name, port, account name, and secret with values from your environment:

CHANGE REPLICATION SOURCE TO
  SOURCE_HOST='source.example.com',
  SOURCE_PORT=3306,
  SOURCE_USER='replication',
  SOURCE_PASSWORD='use-a-secret-manager',
  SOURCE_AUTO_POSITION=1;

SOURCE_AUTO_POSITION=1 tells MySQL 8.4 to negotiate the missing transactions by GTID. The statement stores connection and replication parameters for the replica. Do not publish or commit a production password in this statement; use a protected deployment mechanism and rotate credentials according to policy.

If an old channel definition is present, inspect it before changing it. Changing connection parameters while a receiver or applier thread is running can fail or leave you diagnosing a mixture of old and new settings. Stop the channel first and confirm its state.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start the channel and verify it

Start replication on the replica:

START REPLICA;
SHOW REPLICA STATUSG

Read the status as a set of related checks rather than relying on one green-looking field. Confirm all of the following:

  • Replica_IO_Running reports that the receiver thread is running.
  • Replica_SQL_Running reports that the applier thread is running.
  • Source_Host and the channel information identify the intended source.
  • Last_IO_Error and Last_SQL_Error are empty.
  • The reported GTID and relay positions advance after new source transactions.
  • Lag indicators are understood in context; a zero or low value does not prove that every workload is safe during a source failure.

Perform a controlled end-to-end test: create a uniquely named test row or table in a maintenance-safe schema on the source, wait for the replica to apply it, and query the replica. Remove the test object when finished. This validates network access, account permissions, binary logging, the receiver, and the applier together.

Once validation succeeds, restore the intended application write mode on the source. Continue watching the status output and MySQL error logs during the first period of normal traffic.

File-position replication for legacy cases

When GTIDs are unavailable or a compatible legacy process requires coordinates, seed the replica from a consistent snapshot and record the exact source binary-log file and position associated with that snapshot. The values must come from the same consistency boundary as the data loaded into the replica.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure the replica with the source connection details and replace auto-positioning with the recorded coordinates:

CHANGE REPLICATION SOURCE TO
  SOURCE_HOST='source.example.com',
  SOURCE_PORT=3306,
  SOURCE_USER='replication',
  SOURCE_PASSWORD='use-a-secret-manager',
  SOURCE_LOG_FILE='recorded-binlog-file',
  SOURCE_LOG_POS=recorded_position;

Use the exact file name and numeric position captured for that dump or snapshot. Starting from a nearby position can replay transactions that are already in the data, skip transactions that are missing, or produce duplicate-key and data-consistency errors. After the statement, run START REPLICA and inspect SHOW REPLICA STATUSG using the same receiver, applier, host, and error checks as the GTID procedure.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a replica that will not start

The receiver thread is stopped

Check Last_IO_Error. A connection error usually means the source address, TCP port, firewall rule, DNS resolution, TLS requirement, or replication account host restriction is wrong. Test connectivity from the replica host, confirm that MySQL is listening on the intended interface, and verify the account’s allowed source address. Do not solve a connection problem by granting broad administrative privileges.

The applier thread is stopped

Read Last_SQL_Error before changing anything. Duplicate-key, missing-table, and constraint errors commonly indicate that the replica was not seeded consistently, that someone wrote directly to replicated tables, or that file coordinates do not match the loaded data. Preserve the error and relevant status output, stop application writes to the replica, and correct the underlying data or re-seed rather than blindly skipping events.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

GTID auto-positioning reports missing required GTIDs

The source has purged one or more transactions that the replica still needs. Auto-positioning cannot retrieve history that no longer exists in the source’s binary logs. The safe recovery is to re-seed the replica from a fresh consistent snapshot that includes current GTID state, or restore the missing transaction history from an independent archive if your organization maintains one. After re-seeding, repeat CHANGE REPLICATION SOURCE TO with SOURCE_AUTO_POSITION=1 and start the channel again.

The replica starts at the wrong point

For file-position replication, compare the recorded coordinates with the metadata captured at dump time. For GTID replication, compare the replica’s executed and retrieved GTID sets with the source’s retained history. Do not mix a dump from one point with coordinates from another. If the histories cannot be reconciled confidently, stop the channel and provision a new consistent seed.

Replication stops after a restart

Check whether replication startup was intentionally suppressed during setup and whether the channel has been configured to start under your service-management policy. A clean SHOW REPLICA STATUSG result before shutdown does not guarantee that the service will start the channel automatically after reboot. Make startup behavior explicit and verify it during a maintenance test.

Operate the pair safely

Monitor lag, errors, and storage

Monitor receiver and applier state, the latest I/O and SQL errors, transaction progress, relay-log growth, source binary-log disk usage, and the time a replica spends behind the source. Alert on stopped threads and persistent lag rather than treating a single instantaneous lag reading as a complete health signal.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Retain enough binary-log history

Retention must match your recovery and maintenance windows. A replica that is offline longer than the source’s retained history cannot catch up by itself. Coordinate purge policies with backup schedules and planned outages, and verify that archived logs are actually restorable before relying on them.

Keep backups independent

Store backups outside the replica’s failure domain when possible. Test point-in-time recovery and document who can perform a restore. If both servers share the same storage system, credentials, or facility, a single incident can remove the source, replica, and their local backup copies together.

Choose the right replication timing model

Asynchronous replication is the default and generally has the least effect on source commit latency, but it permits a window of potential data loss during an abrupt source failure. MySQL also documents semisynchronous and delayed replication as separate operational choices. Semisynchronous operation can make the source wait for acknowledgement from a replica, while delayed replication intentionally keeps a replica behind; select either only after defining recovery-point, latency, and failure-handling requirements.

Plan a promotion instead of assuming failover

Replication does not elect a new source or redirect applications by itself. A promotion runbook should identify the replica to promote, stop or fence the failed source, confirm the replica has applied the required transactions, make the promoted server writable, and redirect clients. GTIDs simplify identifying common transaction history, but they do not remove the need for a tested operational procedure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When two self-managed servers are not the right answer

Running the source and replica yourself is reasonable when you can maintain operating-system security, MySQL upgrades, backups, monitoring, network controls, and recovery drills. Consider a managed database service or a larger high-availability design when your team cannot provide those controls, when the required recovery time is shorter than manual promotion allows, or when the dataset and write rate make a single replica insufficient.

For a straightforward MySQL 8.4 pair, the reliable sequence is: establish identities and connectivity, enable source binary logging, create a restricted account, take a consistent seed, enable GTIDs on both servers, configure SOURCE_AUTO_POSITION=1, start the replica, test a controlled write, and monitor the channel continuously. If the source has already purged required history, do not force the channel forward; re-seed it or restore the missing history first.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.