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 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'...
MySQL Router  has now been configured for the InnoDB cluster 'myCluster'.

The following connection information can be used to connect to the cluster.

Classic MySQL protocol connections to cluster 'myCluster':
- Read/Write Connections: localhost:6446
- Read/Write Connections: /tmp/myrouter/mysql.sock
- Read/Only Connections: localhost:6447
- Read/Only Connections: /tmp/myrouter/mysqlro.sock

X protocol connections to cluster 'myCluster':
- Read/Write Connections: localhost:64460
- Read/Write Connections: /tmp/myrouter/mysqlx.sock
- Read/Only Connections: localhost:64470
- Read/Only Connections: /tmp/myrouter/mysqlxro.sock

shell> cd /tmp/myrouter
shell> ./start.sh

A generated MySQL Router directory looks similar to:

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

data
log
mysqlro.sock
mysqlrouter.conf
mysqlrouter.key
mysqlrouter.pid
mysql.sock
mysqlxro.sock
mysqlx.sock
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 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.