MySQL 8.2 Finally Supports Read/Write Splitting
MySQL 8.2 introduces native read/write splitting via MySQL Router, allowing automatic routing of reads to replicas and writes to the primary in an InnoDB ReplicaSet without any application changes.
MySQL InnoDB ReplicaSet
The article starts by describing a minimal InnoDB ReplicaSet architecture, which consists of a single source instance and one or more asynchronous replicas. Screenshots show the ReplicaSet object status in MySQL Shell.
Starting MySQL Router 8.2
Next, the author configures and launches MySQL Router 8.2. Images illustrate the Router configuration steps and the Router view inside the MySQL Shell ReplicaSet object.
Demonstrating Read/Write Routing
Connecting to the Router on port 6450, the author shows that read operations are automatically directed to a replica, while a transaction start forces routing to the source (primary) without changing the port. A separate screenshot demonstrates the behavior of read‑only transactions.
Router Configuration for Split Routing
The generated Router configuration file contains a bootstrap_rw_split section that enables read/write splitting:
[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 article also notes that the ROUTER SET access_mode= command can be used in a session to explicitly choose the instance type to access.
Conclusion
MySQL Router 8.2’s read/write splitting is a valuable feature that optimizes database performance and scalability while eliminating the need for application‑level routing logic. All read traffic is directed to read‑only replicas, and all write traffic goes to the primary source, simplifying deployment and management.
java1234
Former senior programmer at a Fortune Global 500 company, dedicated to sharing Java expertise. Visit Feng's site: Java Knowledge Sharing, www.java1234.com
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.
