Databases 6 min read

How MySQL Router 8.2 Enables Seamless Read/Write Splitting with InnoDB ReplicaSet

This article demonstrates how MySQL Router 8.2 can automatically route read traffic to replica instances and write traffic to the primary instance in an InnoDB ReplicaSet, providing configuration steps, command examples, and observed behavior without requiring any changes to the application.

Top Architect
Top Architect
Top Architect
How MySQL Router 8.2 Enables Seamless Read/Write Splitting with InnoDB ReplicaSet

MySQL InnoDB ReplicaSet

A ReplicaSet consists of a single source (primary) instance and one or more asynchronous replica instances. The primary handles all write operations, while replicas serve read requests, enabling horizontal scaling of read workloads.

ReplicaSet topology
ReplicaSet topology

The MySQL Shell shows the status of the ReplicaSet object, confirming the presence of the source and its replicas.

ReplicaSet status
ReplicaSet status

Start MySQL Router 8.2

MySQL Router 8.2 can detect read and write traffic and route it accordingly. When a read operation is issued, Router forwards the request to a replica; when a write or a transaction is started, Router directs the request to the primary source.

Router startup
Router startup

The Router appears as a member of the ReplicaSet object in the MySQL Shell, confirming that it has been registered.

Router in ReplicaSet
Router in ReplicaSet

Connecting to MySQL via the read/write port (6450) demonstrates the routing behavior: a simple SELECT hits a replica, while starting a transaction automatically switches to the primary.

Connection test
Connection test

Read‑only transactions show the same routing logic, confirming that Router respects transaction boundaries.

Read‑only transaction
Read‑only transaction

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

At runtime you can override the target instance type for a session using the ROUTER SET access_mode= command, allowing explicit control over whether reads go to primary or replica.

ROUTER SET command
ROUTER SET command

Conclusion

MySQL Router 8.2 fully supports read/write splitting for InnoDB ReplicaSet deployments. This feature improves database performance and scalability by automatically directing read traffic to read‑only replicas and write traffic to the primary instance, all without requiring any changes to the application code.

The approach simplifies database management, enhances user experience, and provides a clear separation between read‑only and read/write workloads.

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.

SQLread/write splittingRouterDatabase ConfigurationInnoDB 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.