Skip to content

MySQL Group Replication — single-primary and multi-primary setup

How to bring up MySQL Group Replication, configure single-primary or multi-primary mode, bootstrap the group, and verify quorum and view-change behaviour.

Group Replication is MySQL’s native built-in clustering layer — a Paxos-based replication plugin that runs an odd number of servers as a logical group, gates each commit on majority agreement, and handles primary election automatically. Combined with MySQL Router and MySQL Shell, it forms an InnoDB Cluster. This article is the operator-grade setup we use when a client needs strict quorum-based MySQL with built-in failover, the configuration of single-primary vs multi-primary mode, and the verification that the group actually converges.

How to verify

Group Replication exposes its state through Performance Schema tables, not through SHOW REPLICA STATUS (because there is no single source-replica relationship).

mysql -e "SELECT * FROM performance_schema.replication_group_members;"
mysql -e "SELECT * FROM performance_schema.replication_group_member_stats\G"
mysql -e "SHOW STATUS LIKE 'group_replication%';"
mysql -e "SELECT @@group_replication_single_primary_mode;"
mysql -e "SELECT * FROM performance_schema.replication_connection_status WHERE channel_name LIKE 'group_replication%';"

replication_group_members.MEMBER_STATE reads ONLINE for a healthy member, RECOVERING while a new member catches up, ERROR after a failure. MEMBER_ROLE is PRIMARY or SECONDARY in single-primary mode; in multi-primary, every member reads PRIMARY.

What’s happening

Group Replication runs a consensus protocol — a variant of Paxos — across an odd-numbered group of MySQL servers. Every write transaction is broadcast to the group, certified against concurrent writes from other members, and committed only if a majority agree. This is the model that gives Group Replication its strong consistency guarantee: a committed transaction is on a majority of members and survives the failure of any minority.

Two modes. Single-primary (the default) elects one member as PRIMARY; only that member accepts writes, secondaries serve reads (read_only). On primary failure, the group elects a new primary automatically — typical failover under 10 seconds. Multi-primary lets every member accept writes; the certification step rejects conflicting transactions with a deterministic ordering. Multi-primary trades latency for write availability and has stricter schema rules (every table needs a primary key, no foreign keys with cascading operations, no SERIALIZABLE isolation).

The group’s state lives in three places: the local data on each member, the GTID set shared across the group, and the in-memory group view. View changes — members joining or leaving — are themselves consensus events recorded in every member’s binlog. A new member catching up uses GTIDs to figure out which transactions it is missing.

InnoDB Cluster is the supported topology: three or more MySQL servers running Group Replication, fronted by MySQL Router (the equivalent of MaxScale or ProxySQL for this product line), managed via MySQL Shell’s dba API.

The procedure

  1. Configure each member with the variables Group Replication needs. The server_uuid must be unique per node and not change; group_replication_group_name must be a UUID that is identical across all members.

    [mysqld]
    server_id                            = 1
    gtid_mode                            = ON
    enforce_gtid_consistency             = ON
    binlog_format                        = ROW
    log_bin                              = binlog
    log_slave_updates                    = ON
    master_info_repository               = TABLE
    relay_log_info_repository            = TABLE
    transaction_write_set_extraction     = XXHASH64
    
    plugin_load_add                      = group_replication.so
    group_replication_group_name         = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
    group_replication_start_on_boot      = OFF
    group_replication_local_address      = '10.0.0.11:33061'
    group_replication_group_seeds        = '10.0.0.11:33061,10.0.0.12:33061,10.0.0.13:33061'
    group_replication_bootstrap_group    = OFF
    group_replication_single_primary_mode = ON
  2. Create the recovery user on every member — Group Replication uses standard async replication to catch up new members.

    SET SQL_LOG_BIN=0;
    CREATE USER 'repl'@'%' IDENTIFIED BY 'REPL_PASS' REQUIRE SSL;
    GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
    GRANT BACKUP_ADMIN, GROUP_REPLICATION_STREAM ON *.* TO 'repl'@'%';
    FLUSH PRIVILEGES;
    SET SQL_LOG_BIN=1;
    CHANGE REPLICATION SOURCE TO SOURCE_USER='repl', SOURCE_PASSWORD='REPL_PASS'
      FOR CHANNEL 'group_replication_recovery';
  3. Bootstrap the group from the first member. Only the first member, only at group birth.

    SET GLOBAL group_replication_bootstrap_group = ON;
    START GROUP_REPLICATION;
    SET GLOBAL group_replication_bootstrap_group = OFF;
    SELECT * FROM performance_schema.replication_group_members;
  4. Join each subsequent member without setting bootstrap_group.

    START GROUP_REPLICATION;
    SELECT * FROM performance_schema.replication_group_members;

    Each join goes through RECOVERING while it pulls missing transactions, then transitions to ONLINE.

  5. Verify single-primary mode behaviour by killing the primary.

    # find the current primary
    mysql -e "SELECT MEMBER_HOST FROM performance_schema.replication_group_members WHERE MEMBER_ROLE='PRIMARY';"
    # stop MySQL on the primary
    sudo systemctl stop mysql
    # on any remaining member
    mysql -e "SELECT * FROM performance_schema.replication_group_members;"

    Within a few seconds the group elects a new primary. The old primary, when restarted, rejoins as a secondary.

  6. For multi-primary mode, change the mode on a quorum-healthy group:

    SELECT group_replication_switch_to_multi_primary_mode();
    SELECT * FROM performance_schema.replication_group_members;
  7. Put MySQL Router in front of the group so applications connect to a router endpoint, not directly to a member.

    mysqlrouter --bootstrap repl@10.0.0.11:3306 --directory /opt/mysqlrouter --user mysqlrouter
    sudo systemctl start mysqlrouter

Common pitfalls

  • Two-node groups — Group Replication needs majority consensus; two nodes have no majority on partition. Always odd numbers (3, 5, 7).
  • group_replication_start_on_boot=ON on every member — a full power outage with this flag on causes all members to race the bootstrap; if none is set as bootstrap_group, none starts.
  • Missing primary key on a table — Group Replication rejects DML on tables without primary keys. In multi-primary, certification needs the primary key to deduplicate concurrent writes; in single-primary, the rule is the same.
  • Foreign keys with cascade in multi-primary — cascading updates conflict with the certification model. Move to single-primary or remove cascading actions.
  • Network ports — the group communicates on group_replication_local_address (often 33061) in addition to 3306. The firewall must permit it among members.

Group Replication is the natural fit when a client wants MySQL clustering shipped from the same source as MySQL itself — no third-party plugin, no Galera certification layer, just MySQL with consensus. In the engagements we run, Group Replication setups are paired with MySQL Router as the front door, the group_replication consumers are mined for the view-change events that signal split brains or flapping, and the failover behaviour is rehearsed against a drill. For the broader pattern of operating MySQL with this level of clustering, see /en/solutions/clustered-environments/.