Databases 5 min read

Enable Read/Write Splitting with MySQL Router 8.2 and InnoDB ReplicaSet

This guide shows how to set up MySQL InnoDB ReplicaSet, start MySQL Router 8.2, configure read/write split routing, and verify that reads are directed to replicas while writes go to the primary instance, all without modifying application code.

Top Architect
Top Architect
Top Architect
Enable Read/Write Splitting with MySQL Router 8.2 and InnoDB ReplicaSet

MySQL InnoDB ReplicaSet

A ReplicaSet consists of a single source (primary) instance and one or more asynchronous replica instances, providing read scalability while keeping data synchronized.

ReplicaSet topology diagram
ReplicaSet topology diagram

The MySQL Shell displays the status of the ReplicaSet object, confirming the primary and replica roles.

ReplicaSet status in MySQL Shell
ReplicaSet status in MySQL Shell

Starting MySQL Router 8.2

Configure and launch MySQL Router to enable read/write split routing. The router is started with the default read/write port 6450.

MySQL Router startup screen
MySQL Router startup screen

After starting, the router appears as a member of the ReplicaSet object in MySQL Shell.

Router listed in ReplicaSet
Router listed in ReplicaSet

Connecting to the router on port 6450 routes read operations to replicas and write operations to the primary. Starting a transaction automatically targets the primary, while read‑only transactions stay on replicas.

Read/write routing behavior
Read/write routing behavior

Router Configuration for Read/Write Split

[routing:bootstrap_rw_split]
bind_address=0.0.0.0
bind_port=6450
destinations=metadata-cache://myreplica/?role=PRIMARY_AND_SECONDARY
routing_strategy=round-robin
protocol=classic
connection_sharing=1
client_ssl_mode=PREFERRED
server_ssl_mode=PREFERRED
access_mode=auto

The generated configuration file shows the read/write split settings. You can also change the access mode for a session with the ROUTER SET access_mode= command.

ROUTER SET command example
ROUTER SET command example

Conclusion

MySQL Router 8.2 fully supports read/write splitting, allowing all read traffic to be automatically directed to read‑only instances and all write traffic to the primary instance. This feature improves database performance and scalability without requiring any changes to the application code.

databaseInnoDBMySQLRouterReplicaSetReadWriteSplit
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.