MySQL Router is a building block for high availability (HA) solutions. It simplifies application development by intelligently routing connections to MySQL servers for increased performance and reliability.
MySQL Router is part of InnoDB Cluster and is lightweight middleware that provides transparent routing between your application and back-end MySQL servers. It is used for a wide variety of use cases, such as providing high availability and scalability by routing database traffic to appropriate back-end MySQL servers. The pluggable architecture also enables developers to extend MySQL Router for custom use cases.
MySQL Group Replication replicates databases across multiple servers while performing automatic failover in the event of a server failure. When used with a InnoDB Cluster, MySQL Router acts as a proxy to hide the multiple MySQL instances on your network and map the data requests to one of the cluster instances. As long as there are enough online replicas and communication between the components is intact, applications are able to contact one of them. MySQL Router also makes this possible by having applications connect to MySQL Router instead of directly to MySQL.
For more information on the installation of MySQL Router, see Installing MySQL Router.
For more information on the deployment of MySQL Router, see Deploying MySQL Router.
For more information on the configuration of MySQL Router, see Configuring MySQL Router.
When you have set up an InnoDB Cluster and have MySQL Router running, you can test the InnoDB Cluster and MySQL Router setup using MySQL Shell Consoles.
By default, InnoDB Cluster can be reached by connecting to:
-
classic MySQL protocol
Read/Write Connections: instance-address: port 6446
Read/Only Connections: instance-address: port 6447
-
X Protocol
Read/Write Connections: instance-address: port 6448
Read/Only Connections: instance-address: port 6449
Instead of connecting to one of the MySQL server instances directly, connect through the MySQL Router.
-
Issue the following connection command, where the user is
demo-user
and the address of the instance isdemo-instance
, and classic MySQL protocol is being used:shell.connect ('demo-user@demo-instance:6446')
Provide the root password to connect to the InnoDB Cluster.
-
Check the status of the InnoDB Cluster by creating a variable
cluster
and assigning it with the value of thedba.getCluster()
JavaScript method:cluster = dba.getCluster()
cluster.status()
-
Switch to SQL mode:
\sql
-
Query the port the instance is running on, by issuing:
SELECT @@port; +--------+ | @@port | +--------+ | 3310 | +--------+ 1 row in set (0.0007 sec)
In this example, InnoDB Cluster is running on port 3310, so MySQL Router has been configured correctly and is running successfully.