ProxySQL MySQL MySQL · DBA · Configuration

ProxySQLHostgroups

Learn ProxySQL hostgroup concepts, design patterns for read/write split, mysql_replication_hostgroups and mysql_group_replication_hostgroups configuration.

A hostgroup is a logical collection of MySQL backend servers in ProxySQL. Instead of routing to individual servers, ProxySQL routes traffic to hostgroups — and then load balances across all servers within that group. This abstraction makes it easy to add/remove servers without changing routing rules.

HostgroupRoleContains
10Writers (Master)MySQL Master only
20Readers (Replicas)All MySQL Replicas
HostgroupRoleContains
10WritersMySQL Master
20ReadersMySQL Master + All Replicas
💡 Note: Adding master to reader hostgroup ensures reads still work even if all replicas fail.
HostgroupRole
10App1 Writers
11App1 Readers
20App2 Writers
21App2 Readers

This table tells ProxySQL which hostgroup is the writer and which is the reader for MySQL traditional replication. ProxySQL monitors the read_only variable on all servers and automatically moves them between hostgroups.

SQL — Configure Replication Hostgroups
-- Configure Read/Write split hostgroups
INSERT INTO mysql_replication_hostgroups
  (writer_hostgroup, reader_hostgroup, check_type, comment)
VALUES
  (10, 20, 'read_only', 'MySQL Replication RW Split');

LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;

-- Verify
SELECT * FROM mysql_replication_hostgroups;
SELECT * FROM runtime_mysql_replication_hostgroups;
ColumnDescription
writer_hostgroupHostgroup for servers where read_only=OFF (master)
reader_hostgroupHostgroup for servers where read_only=ON (replicas)
check_typeread_only (standard) or innodb_read_only or super_read_only
commentFree text

For MySQL Group Replication or InnoDB Cluster, use this table instead:

SQL — Group Replication Hostgroups
-- For MySQL Group Replication
INSERT INTO mysql_group_replication_hostgroups
  (writer_hostgroup, backup_writer_hostgroup, reader_hostgroup,
   offline_hostgroup, active, max_writers, writer_is_also_reader,
   max_transactions_behind, comment)
VALUES
  (10, 30, 20, 40, 1, 1, 1, 0, 'Group Replication Setup');

LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
ColumnDescription
writer_hostgroupPrimary/writer node hostgroup
backup_writer_hostgroupBackup writers (multi-primary mode)
reader_hostgroupRead replicas hostgroup
offline_hostgroupServers that are offline/recovering go here
max_writersMaximum number of writer nodes (usually 1)
writer_is_also_reader1 = writer also serves reads; 0 = writer only does writes
max_transactions_behindMax allowed transactions behind primary before SHUNNED
SQL — Check Hostgroup Status
-- See which servers are in which hostgroup RIGHT NOW (runtime)
SELECT hostgroup_id, hostname, port, status
FROM runtime_mysql_servers
ORDER BY hostgroup_id, hostname;

-- Check which servers ProxySQL thinks are read_only
SELECT hostname, port, time_start_us, success_time_us, read_only, error
FROM monitor.mysql_server_read_only_log
ORDER BY time_start_us DESC
LIMIT 20;