Databases 6 min read

How MySQL 8.2 Router Enables Seamless Read/Write Splitting

Oracle’s MySQL 8.2 introduces built‑in read/write splitting via MySQL Router, allowing write traffic to target primary instances while reads are automatically routed to secondary replicas, with configuration examples, command‑line bootstrap, routing settings, and practical observations on transaction behavior.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
How MySQL 8.2 Router Enables Seamless Read/Write Splitting

Introduction

Oracle recently announced that MySQL 8.2 is generally available and includes native support for read/write splitting. This feature lets applications direct all write traffic to a primary (read‑write) instance while routing read traffic to read‑only replicas, improving performance and scalability.

Frederic Descamps (MySQL Community Manager) explains that the router now can detect read and write traffic and route it to the appropriate InnoDB Cluster primary or to an asynchronous source for writes and to secondary instances for reads.
Peter Zaitsev (Founder, Percona) notes that while the feature is significant, it is unclear what consistency guarantees reads have—whether stale data may be returned and for how long. He also mentions that the default read/write port (6450) connects to replicas for reads and to the source for writes, with transaction behavior affecting routing.

Read/Write Splitting Overview

In large‑scale deployments, applications traditionally split read and write traffic manually. MySQL 8.2’s Router automates this by classifying each query as read or write and sending it to the appropriate backend without requiring application changes.

MySQL InnoDB ReplicaSet Example

The author demonstrates the simplest architecture: a MySQL InnoDB ReplicaSet consisting of one source instance and one or more asynchronous replicas.

ReplicaSet topology
ReplicaSet topology

The following screenshot shows the ReplicaSet object status in MySQL Shell.

ReplicaSet status
ReplicaSet status

Bootstrapping MySQL Router 8.2

To start the router, run the bootstrap command:

mysqlrouter --bootstrap [email protected]:3306 --user mysqlrouter
Router bootstrap output
Router bootstrap output

The router appears in the MySQL Shell ReplicaSet object.

Router in ReplicaSet
Router in ReplicaSet

Connecting to the read/write port (6450) shows that reads go to a replica, while starting a transaction forces the connection to the primary source.

Read/write routing behavior
Read/write routing behavior

A separate screenshot illustrates the difference when using a read‑only transaction.

Read‑only transaction routing
Read‑only transaction routing

Router Configuration for R/W Split

The generated configuration file contains a routing section that implements the 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

During a session you can explicitly set the access mode with the ROUTER SET access_mode= command to force routing to a specific instance type.

Router SET command example
Router SET command example

Conclusion

MySQL Router 8.2 fully supports read/write splitting, allowing databases to scale and perform better without any code changes in the application. The configuration directs all reads to read‑only instances and all writes to the primary, simplifying deployment and improving user experience.

This setup lets you route all read traffic to replicas and all write traffic to the primary.

The feature enhances overall user experience and streamlines database management.

Read‑write instances are primary or source instances; read‑only instances are replicas (secondary members of an InnoDB Cluster, ReplicaSet, or Replication Cluster).

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 splittingDatabase PerformanceMySQL RouterInnoDB Cluster
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

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.