5.2 Connect with Port Forwarding

Optionally use port forwarding to create a redirection from your local machine to easily use a MySQL client such as MySQL Workbench. We'll use port 3306 for a read-write connection to the primary on port 6446:

Press CTRL+C to copy
$> kubectl port-forward service/mycluster 3306 Forwarding from 127.0.0.1:3306 -> 6446 Forwarding from [::1]:3306 -> 6446

To test, open a second terminal using the MySQL command line or MySQL Shell with the InnoDB Cluster user's credentials:

Press CTRL+C to copy
$> mysql -h127.0.0.1 -uroot -p

To demonstrate the connection to a local MySQL instance:

Press CTRL+C to copy
mysql> select @@hostname; +-------------+ | @@hostname | +-------------+ | mycluster-0 | +-------------+

Not seeing a port-forward to 127.0.0.1:3306 in this example means a local MySQL installation is likely installed and active on the system.

Using port names instead of port numbers also works:

Press CTRL+C to copy
$> kubectl port-forward service/mycluster mysql Forwarding from 127.0.0.1:3306 -> 6446 Forwarding from [::1]:3306 -> 6446 ^C $> kubectl port-forward service/mycluster mysql-ro Forwarding from 127.0.0.1:6447 -> 6447 Forwarding from [::1]:6447 -> 6447

A list of port names with their associated ports:

Press CTRL+C to copy
mysql: 3306 mysqlx: 33060 mysql-alternate: 6446 mysqlx-alternate: 6448 mysql-ro: 6447 mysqlx-ro: 6449 router-rest: 8443

For a list of all ports used by MySQL services, see MySQL Port Reference. The ports used here are from MySQL Router.