Circular replication lets two MariaDB servers exchange asynchronous updates. GTIDs identify replication progress; they do not resolve conflicting writes or guarantee identical data. This Windows-oriented example is a planning aid for an isolated lab, not a production runbook.
The stages below require an approved backup, restore rehearsal, maintenance plan and version-specific review. Nothing here was executed against a database.
Why GTID instead of file/position?
With the old method, a replica tracks where it is by binlog file name and byte offset, e.g. mariadb-bin.000042 at position 18734. With GTID, every transaction gets a global ID like 1-1-1234 (domain - server - sequence). That gives you:
- Logical replication position.
MASTER_USE_GTID = slave_posstarts from recorded replicated GTIDs, not an automatic comparison of table contents. A seed still needs a position matching its snapshot. - Failover support. GTIDs can help resume on another compatible source that retains the required transactions. Promotion still requires fencing, lag assessment and a tested topology.
- Transactional position tracking. Crash safety depends on transactional storage for
mysql.gtid_slave_posand the applicable data and durability settings. It is not an unconditional no-loss guarantee. - Status evidence.
@@gtid_current_poscombines local and replicated progress. Equal positions alone do not prove equal data; inspect replication errors, lag and an independently planned consistency check. - Fits master-master. Each server has its own domain ID, so the two write streams are tracked separately and don't get mixed up.
What you need
- Two isolated Windows servers on the same currently supported MariaDB release, with matching client tools. Verify support and configuration for the exact release before use.
- Server A: 10.0.0.1
- Server B: 10.0.0.2
- Addresses and paths are illustrative. Use separate generated secrets, restricted peer accounts and verified TLS; do not reuse the original example password.
Where to run commands: open Command Prompt (MariaDB) from the Start menu (or a normal Command Prompt in C:\Program Files\MariaDB 11.x\bin). To get an SQL prompt, run:
mariadb -u root -p
Step 0: Plan peer-only network access
Have the authorized administrator review an inbound rule restricted to the peer address, private interface and intended network profile. Do not expose the database port publicly.
Planning template only: no firewall command is supplied. Server A: allow TCP 3306 only from 10.0.0.2. Server B: allow TCP 3306 only from 10.0.0.1.
Apply the same peer restrictions if using the firewall GUI; verify the effective rules through the organization’s change procedure.
Step 1: Configure Server A
Open my.ini in Notepad as administrator. It lives in the data folder, usually:
C:\Program Files\MariaDB 11.x\data\my.ini
Under the existing [mysqld] section, add:
[mysqld]
server_id = 1
gtid_domain_id = 1
log_bin = mariadb-bin
relay_log = relay-bin
binlog_format = ROW
log_slave_updates = ON
gtid_strict_mode = ON
bind-address = 10.0.0.1
# avoid AUTO_INCREMENT collisions
auto_increment_increment = 2
auto_increment_offset = 1
Leave the lines that are already there (like datadir and port) as they are.
Step 2: Configure Server B
Use the server-specific values below in the same file.
[mysqld]
server_id = 2
gtid_domain_id = 2
log_bin = mariadb-bin
relay_log = relay-bin
binlog_format = ROW
log_slave_updates = ON
gtid_strict_mode = ON
bind-address = 10.0.0.2
auto_increment_increment = 2
auto_increment_offset = 2
server_id must be unique. Distinct gtid_domain_id values model independent write streams. Odd/even auto-increment offsets reduce one kind of generated-key collision; they do not prevent conflicting updates, explicit-key collisions or unique-index conflicts.
A restart interrupts service. Schedule it only after configuration review and rollback planning; verify the actual Windows service name before using this illustrative command.
net stop MariaDB
net start MariaDB
Why binlog_format = ROW and not MIXED?
- ROW records row changes rather than re-executing the original SQL. It does not make concurrent writers conflict-free or guarantee identical databases.
- MIXED selects statement or row logging according to the statement and server behavior. Review the version’s documented unsafe-statement rules rather than assuming either mode detects every application conflict.
- Row-based apply can fail on missing rows or duplicate keys, but not every divergence becomes an error. Investigate consistency independently and never skip errors blindly.
- The cost is larger binary logs for big bulk updates. You can reduce that with
binlog_row_image = MINIMAL.
Step 3: Create the replication user (on both servers)
Create a dedicated least-privilege replication account for the exact remote peer on each server. The following commented template is not directly runnable; provision secrets securely and review binary-log handling rather than disabling logging casually.
-- Reviewed template; substitute peer and generated secret securely.
-- On A the peer is 10.0.0.2; on B it is 10.0.0.1.
-- CREATE USER 'repl'@'EXACT_PEER' IDENTIFIED BY 'GENERATED_SECRET' REQUIRE SSL;
-- GRANT REPLICATION SLAVE ON *.* TO 'repl'@'EXACT_PEER';
Step 4: Start from the same data
New empty lab servers. Verify there is no required data, recovery history or dependent replica. Empty databases do not justify deleting binary logs. This guide does not instruct RESET MASTER.
RESET MASTER is intentionally omitted: it deletes binary logs.
Server A already contains data. Seed only an empty, isolated B from a reviewed consistent backup. Stop application writes and DDL for the agreed snapshot procedure; verify a restore before enabling replication.
- On A: choose the application databases explicitly. A
--single-transactiondump gives a consistent snapshot for InnoDB tables; other engines require explicit support for the required consistent snapshot. The dump does not protect against concurrent DDL. Review routines, events, system accounts and a GTID position tied to that snapshot; a blanket--all-databasesimport is not a safe default. - Transfer the backup through an approved encrypted channel with restricted access and integrity verification. Dumps can contain sensitive records and account material.
- Read the snapshot’s actual replication coordinates and the generated GTID statements from the reviewed dump. Their form depends on options and version;
1-1-1234is only a fictional illustration, never a value to copy into a real server. - On isolated B: restore only after reviewing every statement and any embedded replication settings. Import can replace objects and accounts; suppressing binary logging is privileged and changes recovery history. Use the approved restore procedure, not a generic
SOURCEsequence. - Set
gtid_slave_posonly as part of the approved restore, while replication is stopped, to the position proven to match the imported snapshot. Review existing local GTIDs before forming the reverse channel.
Step 5: Make Server B replicate from A
In the SQL prompt on Server B:
-- Non-executing configuration template; review seeded GTIDs first.
-- CHANGE MASTER TO
-- MASTER_HOST = 'db-a.example.internal',
-- MASTER_USER = 'repl',
-- MASTER_PASSWORD = 'GENERATED_SECRET',
-- MASTER_PORT = 3306,
-- MASTER_USE_GTID = slave_pos,
-- MASTER_SSL = 1,
-- MASTER_SSL_CA = 'C:/approved-ca/ca.pem',
-- MASTER_SSL_VERIFY_SERVER_CERT = 1;
-- Start only after certificate-name and snapshot checks pass.
Step 6: Make Server A replicate from B
In the SQL prompt on Server A (this is what makes it master-master):
-- Non-executing configuration template; review seeded GTIDs first.
-- CHANGE MASTER TO
-- MASTER_HOST = 'db-b.example.internal',
-- MASTER_USER = 'repl',
-- MASTER_PASSWORD = 'GENERATED_SECRET',
-- MASTER_PORT = 3306,
-- MASTER_USE_GTID = slave_pos,
-- MASTER_SSL = 1,
-- MASTER_SSL_CA = 'C:/approved-ca/ca.pem',
-- MASTER_SSL_VERIFY_SERVER_CERT = 1;
-- Start only after certificate-name and snapshot checks pass.
GTID removes the file/offset from this connection template, not the need to validate snapshot history, retained logs and each channel’s start position.
Step 7: Check the status
On both servers:
SHOW SLAVE STATUS\G
Look for:
Slave_IO_Running: YesSlave_SQL_Running: YesUsing_Gtid: Slave_PosSeconds_Behind_Master: 0is a lag indicator, not proof that every source transaction is present or that the data is identical.Last_Erroris empty
You can also compare GTID positions:
SELECT @@gtid_binlog_pos, @@gtid_slave_pos, @@gtid_current_pos;
Step 8: Test it both ways
On Server A:
CREATE DATABASE repl_test;
CREATE TABLE repl_test.t (id INT AUTO_INCREMENT PRIMARY KEY, src VARCHAR(10));
INSERT INTO repl_test.t (src) VALUES ('A');
On Server B:
INSERT INTO repl_test.t (src) VALUES ('B');
SELECT * FROM repl_test.t;
In the disposable lab, compare the two rows with SELECT on A after replication catches up. This is a smoke test, not consistency or failover certification. DROP DATABASE repl_test; permanently removes that database and must be separately checked and authorized.
Quick troubleshooting
- Connection failure: inspect peer-only firewall rules,
bind-address, account host matching, TLS trust and certificate names. A plainmariadb -h 10.0.0.1 -u repl -pconnection alone does not validate the replication TLS configuration. - MariaDB service won't start after editing my.ini: check for a typo, and look at the
.errfile in the data folder. - Duplicate key or SQL errors: possible causes include conflicting writes, schema differences and a bad seed. Stop the affected workflow and preserve evidence. Diagnose before a reviewed repair or reseed; do not skip a transaction or assume restarting fixes it.
- Need to see where each server is?
SELECT @@gtid_current_pos;on both.
Good practices
- Avoid writing the same rows on both servers at the same time; replication is asynchronous and conflicts are not resolved automatically.
- A single active writer can reduce conflicts. A standby and proxy still need fencing, routing policy, lag limits and tested recovery; a proxy alone does not make failover safe.
- Monitor
SHOW SLAVE STATUSon both servers. - Keep backups. Replication copies mistakes too.
The result is a design for GTID-based circular replication, conditional on consistent seeding, verified TLS, conflict control and independent testing. Replication is neither a backup nor a guarantee of zero data loss.