MySQL Router 9.0  /  General Information  /  Connection Routing

1.3 Connection Routing

Connection routing means redirecting MySQL connections to an available MySQL server. MySQL packets are routed in their entirety without inspection. For an example deployment using basic connection routing, see Section 3.3, “Basic Connection Routing”.

Applications connect to MySQL Router and not directly to MySQL Server, and if the connection fails then applications are designed to retry the connection because MySQL Router selects a new MySQL server after failed attempts. This is also called simple redirect connection routing because it requires the application to retry the connection. That is, if a connection from MySQL Router to the MySQL server is interrupted, the application encounters a connection failure. However, a new connection attempt triggers Router to find and connect to another MySQL server.

Routed servers and routing strategies are defined in a configuration file. For example, the following section tells MySQL Router to listen for connections on port 7002 of the localhost, and then redirect those connections to a MySQL instance defined by the destinations option, including servers running on the localhost listening on ports 3306, 3307, and 3308. We also use the routing_strategy option to use the round robin form of load-balancing. For additional information, see Section 4.3, “Configuration Options”

[routing:simple_redirect]
bind_port = 7002
routing_strategy = round-robin
destinations = localhost:3306,localhost:3307,localhost:3308

This example section is titled routing:simple_redirect. The first part, routing, is the section name used internally to determine which plugin to load. The second part, simple_redirect, is an optional section key to differentiate between other routing strategies.

When a server is no longer reachable, MySQL Router moves to the next server destination in the list and circles back to the first server destination if the list is exhausted as per the round-robin strategy.