Databases 5 min read

How MySQL Router 8.2 Enables Seamless Read/Write Splitting

MySQL Router 8.2 now supports automatic read/write splitting for InnoDB ReplicaSets, allowing reads to be routed to replicas and writes to the primary without any application changes, thereby improving performance and scalability.

macrozheng
macrozheng
macrozheng
How MySQL Router 8.2 Enables Seamless Read/Write Splitting

We have been waiting for MySQL read/write splitting to become usable, and MySQL Router 8.2 now supports it.

In MySQL 8.2, MySQL Router can recognize read and write traffic and route them to the primary instance (for InnoDB Cluster) or to asynchronous replication sources for writes, and to secondary instances or replicas for reads.

MySQL InnoDB ReplicaSet

This setup consists of a single source instance and one or more asynchronous replicas.

The status of the ReplicaSet object in MySQL Shell is shown below.

Start MySQL Router 8.2

Configure and start MySQL Router.

The Router also appears in the MySQL Shell ReplicaSet object.

Connecting to MySQL using the read/write port (6450) demonstrates that read operations go to replicas, while transactions go to the primary source without changing the port.

Using a read‑only transaction shows the difference.

The generated read/write split configuration can be seen in the Router’s configuration file:

<code>[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
</code>

You can also define the instance type to access in a session with the command

ROUTER SET access_mode=

.

Conclusion

MySQL Router 8.2 supports read/write splitting, a valuable feature that can improve database performance and scalability without any changes to the application.

With this configuration, all read traffic is directed to read‑only instances and all write traffic to read‑write instances, enhancing user experience and simplifying database management and deployment.

MySQLRead-Write SplittingRouterDatabase PerformanceInnoDB ReplicaSet
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

login 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.