MySQL Router 8.0  /  Deploying MySQL Router  /  Bootstrapping MySQL Router

3.1 Bootstrapping MySQL Router

Here is a brief example to demonstrate how MySQL Router can be deployed to use an InnoDB cluster using bootstrapping. For additional information, see --bootstrap and the other bootstrap options.

This example creates a standalone MySQL Router instance using the --directory option, enables sockets, and assumes that an InnoDB cluster named myCluster already exists:

shell> mysqlrouter --bootstrap root@localhost:3310 --directory /tmp/myrouter --conf-use-sockets

Please enter MySQL password for root: 

# Bootstrapping MySQL Router instance at '/tmp/myrouter'...

- Checking for old Router accounts
  - No prior Router accounts found
- Creating mysql account 'mysql_router1_b8z6shsk9uyp'@'%' for cluster management
- Storing account in keyring
- Adjusting permissions of generated files
- Creating configuration /tmp/myrouter/mysqlrouter.conf

# MySQL Router configured for the InnoDB cluster 'myCluster'

After this MySQL Router has been started with the generated configuration

    $ mysqlrouter -c /tmp/myrouter/mysqlrouter.conf

the cluster 'myCluster' can be reached by connecting to:

## MySQL Classic protocol

- Read/Write Connections: localhost:6446
- Read/Only Connections:  localhost:6447

## MySQL X protocol

- Read/Write Connections: localhost:64460
- Read/Only Connections:  localhost:64470

At this point the bootstrap process has created a mysqlrouter.conf file with the required files at the directory specified, and the result shows you how to start this MySQL Router instance. A generated MySQL Router directory looks similar to:

shell> ls -l | awk '{print $9}'

data/
log/
mysqlrouter.conf
mysqlrouter.key
run/
start.sh*
stop.sh*

A generated MySQL Router configuration file (mysqlrouter.conf) looks similar to:

# File automatically generated during MySQL Router bootstrap
[DEFAULT]
logging_folder=/tmp/myrouter/log
runtime_folder=/tmp/myrouter/run
data_folder=/tmp/myrouter/data
keyring_path=/tmp/myrouter/data/keyring
master_key_path=/tmp/myrouter/mysqlrouter.key
connect_timeout=15
read_timeout=30
dynamic_state=/tmp/myrouter/data/state.json

[logger]
level = INFO

[metadata_cache:myCluster]
router_id=5
user=mysql_router5_p79mg6q6ytrw
metadata_cluster=myCluster
ttl=0.5

[routing:myCluster_default_rw]
bind_address=0.0.0.0
bind_port=6446
socket=/tmp/myrouter/mysql.sock
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
socket=/tmp/myrouter/mysqlro.sock
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
socket=/tmp/myrouter/mysqlx.sock
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
socket=/tmp/myrouter/mysqlxro.sock
destinations=metadata-cache://myCluster/default?role=SECONDARY
routing_strategy=round-robin
protocol=x

In this example, MySQL Router configured four ports and four sockets. Ports are added by default, and sockets were added by passing in --conf-use-sockets. The InnoDB cluster named "myCluster" is the source of the metadata, and the destinations are using the InnoDB cluster metadata cache to dynamically configure host information. The related command line options:

  • --conf-use-sockets: Optionally enable UNIX domain sockets for all four connection types, as demonstrated in the example.

  • --conf-skip-tcp: Optionally disable TCP ports, an option to pass in with --conf-use-sockets if you only want sockets.

  • --conf-base-port: Optionally change the range of ports rather than using the default ports. This sets the port for classic read-write (PRIMARY) connections, and defaults to 6446.

  • --conf-bind-address: Optionally change the bind_address value for each route.

To demonstrate MySQL Router's behavior, the following client (application) connects to port 6446 but is connected to a MySQL instance on port 3310.

shell> mysql -u root -h 127.0.0.1 -P 6446 -p

...

mysql> select @@port;
+--------+
| @@port |
+--------+
|   3310 |
+--------+
1 row in set (0.00 sec)

For additional examples, see Set Up a MySQL Server Sandbox and Sandbox Deployment of InnoDB Cluster.