MySQL Router 8.4  /  MySQL Router Application  /  Starting MySQL Router

5.1 Starting MySQL Router

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.service

Example 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    [0x700002714000] Connected with metadata server running on 127.0.0.1:3310

The 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:

[routing:devCluster_default_ro]
bind_address=0.0.0.0
bind_port=6447
destinations=metadata-cache://devCluster/default?role=SECONDARY
protocol=classic

See how the name and port 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
fi