Quickly Build a MySQL InnoDB Cluster with Router for High Availability
This guide walks through installing MySQL Shell and Router, deploying three local MySQL instances, creating an InnoDB cluster, adding the instances, configuring MySQL Router, and testing failover to demonstrate a simplified high‑availability setup.
Deploy Multiple MySQL Instances
Using the MySQL Shell client, start the shell and create sandbox instances on ports 3310, 3320, and 3330, each with the password 111111:
$ mysqlsh mysql-js> dba.deployLocalInstance(3310) mysql-js> dba.deployLocalInstance(3320) mysql-js> dba.deployLocalInstance(3330)Initialize InnoDB Cluster
Connect to the first instance and create a cluster named mycluster:
mysql-js> \c root@localhost:3310 mysql-js> cluster = dba.createCluster('mycluster')Add the remaining instances to the cluster:
mysql-js> cluster.addInstance('root@localhost:3320') mysql-js> cluster.addInstance('root@localhost:3330')View Cluster Status
Run cluster.status() to see the JSON status output, confirming all three nodes are online and the primary (HA) role is on 3310.
{
"clusterName": "mycluster",
"defaultReplicaSet": {
"status": "Cluster tolerant to up to ONE failure.",
"topology": {
"localhost:3310": {"status": "ONLINE","role": "HA","mode": "R/W"},
"localhost:3320": {"status": "ONLINE","role": "HA","mode": "R/O"},
"localhost:3330": {"status": "ONLINE","role": "HA","mode": "R/O"}
}
}
}Deploy MySQL Router
Bootstrap the router against the primary instance: sudo mysqlrouter --bootstrap localhost:3310 Provide the administrative MASTER key (the same identifier used when creating the cluster) and note the generated connection endpoints: read/write on localhost:6446, read‑only on localhost:6447.
Start MySQL Router
# mysqlrouter &Connect Through the Router
From a regular user, connect to the router’s read/write endpoint using MySQL Shell: mysqlsh --uri root@localhost:6446 Switch to SQL mode and verify the underlying instance port:
\sql
SELECT @@port;The query returns 3310, confirming the router forwards traffic to the primary.
Failure Simulation
Kill the primary instance to test automatic failover: mysql-js> dba.killLocalInstance(3310) Subsequent queries through the router reconnect to the surviving instance (e.g., 3330), demonstrating seamless failover.
Conclusion
The new MySQL tools dramatically simplify building a high‑availability InnoDB cluster, but this preview method should not be used in production environments.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
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.
