Databases 6 min read

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

Discover how to set up MySQL InnoDB ReplicaSet and configure MySQL Router 8.2 for automatic read/write splitting, enabling reads to be routed to replicas and writes to the primary without code changes, complete with step-by-step commands, configuration snippets, and visual verification.

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

MySQL InnoDB ReplicaSet

The new MySQL read/write splitting feature is finally available. In a large‑scale deployment you normally distribute reads across replicas while writes go to the primary, but the application must manage this routing. MySQL 8.2 introduces MySQL Router support that automatically distinguishes read and write traffic and routes it accordingly.

To illustrate the feature, a minimal architecture is deployed: a single InnoDB ReplicaSet consisting of one source instance and one (or more) asynchronous replicas.

ReplicaSet topology diagram
ReplicaSet topology diagram

The ReplicaSet object status can be inspected from MySQL Shell, showing the source and replica instances.

ReplicaSet status view
ReplicaSet status view

Start MySQL Router 8.2

Next, configure and launch MySQL Router to enable read/write split.

Router startup command
Router startup command

The Router appears as a member of the ReplicaSet in MySQL Shell.

Router listed in ReplicaSet
Router listed in ReplicaSet

Clients connect to the Router using the read/write port (6450). By default, read operations are sent to a replica, while write operations (including transactions) are sent to the source instance without changing the connection parameters.

Client connection screenshot
Client connection screenshot

When a read‑only transaction is used, the Router still routes reads to replicas, demonstrating the split behavior.

Read‑only transaction behavior
Read‑only transaction behavior

The generated Router configuration file contains the read/write split settings:

[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

During a session you can explicitly set the instance type 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 capability improves database performance and scalability without requiring any changes to application code, simplifying deployment and management.

The read/write instances correspond to the primary (source) instance, while the read‑only instances are the replicas within an InnoDB Cluster ReplicaSet or its auxiliary nodes.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mysqlread/write splittingRouterDatabase PerformanceInnoDB ReplicaSet
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.