Table of Contents
The MySQL Router is an executable designed to run on the same machine as the application that uses it. This chapter describes the application including all available options, how to start the application, and how to use the logging feature.
There are a number of options available for controlling the application. Each is listed below with a brief explanation.
[-v|--version] : displays the version
number of the application and exits.
[-h|--help] : displays the list of options
and additional information about the application and exist.
[-c|--config=$lt;path$gt;] : used to
provide a path and file name for the configuration file to
use. Use this option if you want to use a configuration file
located in a folder other than the default locations.
[-a|--extra-config=$lt;path$gt;] : used to
provide an optional, additional configuration file to use. Use
this option if you want to split the configuration file into
two parts for testing, multiple instances of the application
running on the same machine, etc.
The --help option has an added benefit. Along
with the explanation of each of the options, the
--help option also displays the paths used to
find the configuration file. The following excerpt of the
--help output shows an example from a Ubuntu
15.04 machine.
shell> mysqlrouter --help
MySQL Router v2.0.3 on Linux (64-bit) (GPL community edition)
Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Start MySQL Router.
Configuration read from the following files in the given order (enclosed
in parentheses means not available for reading):
/etc/mysqlrouter/mysqlrouter.ini
(/home/user/.mysqlrouter.ini)
...
The configuration section shows the order for the paths that may be used for reading the configuration file. In this case, only the first file is accessible.
Recall the Router requires a configuration file to setup the
routing strategies and to provide paths for its plugins as well as
other controls such as logging. Recall also that the Router will
search a predetermined list of default paths for some platforms.
However, the best way to start the Router is to provide the
configuration file with the --config= option.
An example follows.
shell> mysqlrouter --config=/path/to/file/my_router.ini
2015-10-22 10:51:34 INFO [7f5f66768700] routing:basic_redirect started: listening on localhost:7001; read-write
2015-10-22 10:51:34 INFO [7f5f65f67700] routing:read_only_redirect started: listening on localhost:7002; read-only
Here we see the Router has started as a console application and has reported its routing strategies. Notice that the Router is listening on two ports and that the name of each routing strategy is listed.
For example, the first strategy is listed as
routing:basic_redirect, is listening on port
7001 and its mode is
read-write. The corresponding section in the
configuration file is shown below.
[routing:basic_redirect] bind_address = localhost:7001 mode = read-write destinations = localhost:13001,localhost:13002,localhost:13003
Notice that 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 handy if you are running several instances of the Router or are using the extra configuration file option.
Similarly, the second strategy is listed as
routing:read_only_redirect, is listening on
port 7002 and its mode is
read-only. The corresponding section in the
configuration file is shown below.
[routing:read_only_redirect] bind_address = localhost:7002 mode = read-only destinations = localhost:3006,localhost:3307
To stop the Router, issue a CTRL +
C in the console or issue a
SIGTERMsignal to stop the application. For
example, you could issue the following command to send the
SIGTERM to the application. Note that we use
the .pid file for the application.
shell> kill -SIGTERM <pid>
In this case, the <pid> is the process id of the mysqlrouter application.
The logging feature can be handy for developing and testing your
application and deployment of the MySQL Router. To use logging, you
must turn it on in the configuration file under a section named
logging. An example is shown below.
[logger] level = INFO
By default, all logs are sent to the console. Alternatively, you
can optionally store the log in a file. To do so, specify a
logging_folder path for the logging file in the
DEFAULTS section in the configuration file as
shown below. The logging file will be named
mysqlrouter.log.
[DEFAULT] logging_folder = /path/to/folder plugin_folder = /usr/local/lib/mysqlrouter config_folder = /etc/mysql runtime_folder = /var/run
When logging to a file, the console output is suppressed and all messages go to the file except for a reminder notice as shown below. Thus, you can either log messages to the console, which is the default, or specify a logging path in the configuration file to log to a file.
Logging to /path/to/folder/mysqlrouter.log
There are two common logging modes:
INFO: which displays only informational
messages like those shown above, and is the default mode
DEBUG: which shows messages generated
inside the Router source code for use in diagnostics. The
DEBUG mode presents a lot of information
concerning the inner workings of the Router. While it may not
be of interest to the application, use of the
DEBUG mode may be helpful if you encounter
a problem or the Router is not behaving as you expect.
The following example shows what the messages would look like for
a logging mode of DEBUG. Notice both
INFO and DEBUG messages are
shown.
2015-10-22 11:21:07 INFO [7fdd091f8700] routing:read_only_redirect started: listening on localhost:7002; read-only 2015-10-22 11:21:07 INFO [7fdd119f9700] routing:basic_redirect started: listening on localhost:7001; read-write 2015-10-22 11:27:09 DEBUG [7fdd0bfff700] Trying server localhost:13001 (index 0) 2015-10-22 11:27:09 DEBUG [7fdd0bfff700] routing:basic_redirect [127.0.0.1]:49661 - [127.0.0.1]:13001 2015-10-22 11:27:41 DEBUG [7fdd0bfff700] Routing stopped (up:301b;down:201b) 2015-10-22 11:28:07 DEBUG [7fdd0bfff700] Trying server localhost:13001 (index 0) 2015-10-22 11:28:07 DEBUG [7fdd0bfff700] MySQL Server localhost:13001: Connection refused (111) 2015-10-22 11:28:07 DEBUG [7fdd0bfff700] Trying server localhost:13002 (index 1) 2015-10-22 11:28:07 DEBUG [7fdd0bfff700] routing:basic_redirect [127.0.0.1]:49663 - [127.0.0.1]:13002
This example was taken from a log file rather than console output.
Notice in the debug statements we see that the routing redirects
were recorded. Thus, if you want to see when these occur, you may
want to use the DEBUG logging mode.
The next chapter discusses the plugins used with MySQL Router.