MySQL Router 8.0  /  ...  /  Configuration File Example

4.3.3 Configuration File Example

Here is a basic connection routing example to a MySQL InnoDB cluster named mycluster. Both classic and X protocols are enabled, it uses TCP/IP connections instead of Unix domain sockets, and it was generated using --bootstrap as a standalone configuration with --directory set to /opt/routers/myrouter.

In this example, read-write (primary) traffic is sent to port 6446 (classic) or 64460 (x), and read-only (secondaries) are accessed using port 6447 (classic) or 64470 (x).

The routing section keys (such as mycluster_default_rw) are optional, but using these descriptive section keys is helpful for debugging, and also allows multiple configuration sections for the same plugin.

The destinations option references metadata-cache to utilize InnoDB cluster's metadata cache that dynamically configures host information. Alternatively, destinations could be a comma-separated list of hosts to accommodate basic connection routing without InnoDB cluster.

# File automatically generated during MySQL Router bootstrap
[DEFAULT]
logging_folder=/opt/routers/myrouter/log
runtime_folder=/opt/routers/myrouter/run
data_folder=/opt/routers/myrouter/data
keyring_path=/opt/routers/router/data/keyring
master_key_path=/opt/routers/myrouter/mysqlrouter.key
connect_timeout=30
read_timeout=30

[logger]
level = INFO

[metadata_cache:mycluster]
router_id=5
bootstrap_server_addresses=mysql://localhost:3310,mysql://localhost:3320,mysql://localhost:3330
user=mysql_router5_6owf3spq1c6n
metadata_cluster=mycluster
ttl=5

[routing:mycluster_default_rw]
bind_address=0.0.0.0
bind_port=6446
destinations=metadata-cache://mycluster/default?role=PRIMARY
routing_strategy=round-robin
protocol=classic

[routing:mycluster_default_ro]
bind_address=0.0.0.0
bind_port=6447
destinations=metadata-cache://mycluster/default?role=SECONDARY
routing_strategy=round-robin
protocol=classic

[routing:mycluster_default_x_rw]
bind_address=0.0.0.0
bind_port=64460
destinations=metadata-cache://mycluster/default?role=PRIMARY
routing_strategy=round-robin
protocol=x

[routing:mycluster_default_x_ro]
bind_address=0.0.0.0
bind_port=64470
destinations=metadata-cache://mycluster/default?role=SECONDARY
routing_strategy=round-robin
protocol=x