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.
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.
The MySQL Shell displays the status of the ReplicaSet object, confirming the primary and replica roles.
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.
After starting, the router appears as a member of the ReplicaSet object in MySQL Shell.
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.
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=autoThe 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.
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.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
