MySQL Router requires a configuration file. Although Router searches a predetermined list of default paths for the configuration file, it is common to start Router by passing in a configuration file with the --config option.
The process of configuring MySQL Router to automatically start when the host reboots is similar to the steps needed for MySQL server, which is described at Starting and Stopping MySQL Automatically.
For example, when using systemd:
$> sudo systemctl start mysqlrouter.service $> sudo systemctl enable mysqlrouter.serviceExample Log Output
Starting MySQL Router generates several log entries, for example when connecting to a sandboxed InnoDB Cluster:
$> mysqlrouter --config=/path/to/file/my_router.conf ^C $> less /path/to/log/mysqlrouter.log 2019-04-07 16:30:49 INFO [0x7000022fc000] [routing:devCluster_default_ro] started: listening on 0.0.0.0:6447; read-only 2019-04-07 16:30:49 INFO [0x70000237f000] [routing:devCluster_default_rw] started: listening on 0.0.0.0:6446; read-write 2019-04-07 16:30:49 INFO [0x700002402000] [routing:devCluster_default_x_ro] started: listening on 0.0.0.0:64470; read-only 2019-04-07 16:30:49 INFO [0x700002485000] [routing:devCluster_default_x_rw] started: listening on 0.0.0.0:64460; read-write 2019-04-07 16:30:49 INFO [0x700002279000] Starting Metadata Cache 2019-04-07 16:30:49 INFO [0x700002279000] Connections using ssl_mode 'PREFERRED' 2019-04-07 16:30:49 INFO [0x700002279000] Connected with metadata server running on 127.0.0.1:3310 2019-04-07 16:30:49 INFO [0x700002279000] Changes detected in cluster 'devCluster' after metadata refresh 2019-04-07 16:30:49 INFO [0x700002279000] Metadata for cluster 'devCluster' has 1 replicasets: 2019-04-07 16:30:49 INFO [0x700002279000] 'default' (3 members, single-master) 2019-04-07 16:30:49 INFO [0x700002279000] localhost:3310 / 33100 - role=HA mode=RW 2019-04-07 16:30:49 INFO [0x700002279000] localhost:3320 / 33200 - role=HA mode=RO 2019-04-07 16:30:49 INFO [0x700002279000] localhost:3330 / 33300 - role=HA mode=RO 2019-04-07 16:30:49 INFO [0x700002714000] Connected with metadata server running on 127.0.0.1:3310The log shows that MySQL Router is listening on four ports, lists the active routing strategies by name, InnoDB Cluster information, and more.
For example, the first line lists the active routing strategy named routing:devCluster_default_ro, is listening on port 6447, and its mode is read-only. The corresponding section in the MySQL Router configuration file looks similar to:
See how the name, port, and mode were taken directly from the configuration file. In this way, you can quickly determine which routing strategies are active. This could be particularly useful if running several instances of MySQL Router, or if multiple configuration files are loaded.
On Windows, MySQL Router can install, remove, or start the service. By default, the service name is MySQLRouter. For additional information, see the --service and related command line options for Windows services.
Example Start and Stop Scripts
Bootstrapping MySQL Router with the --directory option generates bash scripts to start and stop MySQL Router, which look similar to the following:
// *** start.sh *********************** // #!/bin/bash basedir=/opt/myrouter ROUTER_PID=$basedir/mysqlrouter.pid /usr/bin/mysqlrouter -c $basedir/mysqlrouter.conf & disown %- // *** stop.sh *********************** // if [ -f /opt/myrouter/mysqlrouter.pid ]; then kill -HUP `cat /opt/myrouter/mysqlrouter.pid` rm -f /opt/myrouter/mysqlrouter.pid fiPerformance Recommendations
For best performance, MySQL Router is typically installed on the same host as the application that uses it. Possible reasons include:
To allow local UNIX domain socket connections to the application, instead of TCP/IP.
Note
Unix domain sockets can function with applications connecting to MySQL Router, but not for MySQL Router connecting to a MySQL Server.
To decrease network latency.
To allow MySQL Router to connect to MySQL without requiring extra accounts for the Router's host, for MySQL accounts that are created specifically for application hosts such as instead of a value like myapp@%.
Typically application servers are easiest to scale.
You can run multiple MySQL Router instances on your network, and you do not need to isolate MySQL Router to a single machine. This is because MySQL Router has no affinity for any particular server or host.
Figure 3.1 Example MySQL Router Deployment