MySQL Router is lightweight middleware that provides transparent routing between your application and any backend MySQL Servers. It can be used for a wide variety of use cases, such as providing high availability and scalability by effectively routing database traffic to appropriate backend MySQL Servers. The pluggable architecture also enables developers to extend MySQL Router for custom use cases. Show FailoverTypically, a highly available MySQL setup consists of a single primary and multiple replicas and it is up to the application to handle failover, in case the MySQL primary becomes unavailable. Using MySQL Router, application connections will be transparently routed based on load balancing policy, without implementing custom application code. Load BalancingMySQL Router provides additional scalability and performance by distributing database connections across a pool of servers. For example, if you have a replicated set of MySQL Servers, MySQL Router can distribute application connections to them in a round-robin fashion. Pluggable ArchitectureMySQL Router's pluggable architecture allows MySQL developers to easily extend the product with additional features, as well as providing MySQL users with the ability to create their own custom plugins providing endless possibilities. MySQL Router currently ships with a number of core plugins, including:
MySQL Router transparently routes connections within a high availability group Additional Resources
The Connection Routing plugin performs connection-based routing, meaning it forwards packets to the server without inspecting them. This is a simplistic approach that provides high throughput. For additional general information about connection routing, see Section 1.3, “Connection Routing”. A simple connection-based routing setup is shown below. These and additional options are documented under Section 4.3.3, “Configuration File Options”.
Here we use connection routing to round-robin MySQL connections to three MySQL servers on port 7001 as defined by round-robin
Note Before MySQL Router 8.0, the now deprecated
Assuming all three MySQL instances are running, next start MySQL Router by passing in the configuration file:
Now MySQL Router is listening to port's 7001 and 7002 and sends requests to the appropriate MySQL instances. For example:
That will first connect to foo.example.org, and then bar.example.org next, then baz.example.org, and the fourth call goes back to foo.example.org. Instead, we configured port 7002 behavior differently:
That first connects to foo.example.org, and additional requests will continue connecting to foo.example.org until there is a failure, at which
point bar.example.org is now used. For additional information about this behavior, see 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. For additional details about how Router is part of InnoDB Cluster, see MySQL AdminAPI. IntroductionFor client applications to handle failover, they need to be aware of the InnoDB cluster topology and know which MySQL instance is the PRIMARY. While it is possible for applications to implement that logic, MySQL Router can provide and handle this functionality for you. MySQL uses Group Replication to replicate databases across multiple servers while performing automatic failover in the event of a server failure. When used with a MySQL 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 will be able to contact one of them. MySQL Router also makes this possible by having applications connect to MySQL Router instead of directly to MySQL. Deploying Router with MySQL InnoDB ClusterThe recommended deployment model for MySQL Router is with InnoDB Cluster, with Router sitting on the same host as the application. The steps for deploying MySQL Router with an InnoDB Cluster after configuring the cluster are:
For example, after creating a MySQL InnoDB Cluster, you might configure MySQL Router using:
This example bootstraps MySQL Router to an existing InnoDB Cluster where:
See |