4.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:

$> kubectl port-forward service/mycluster 3306

Forwarding from -> 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:

$> mysql -h127.0.0.1 -uroot -p

To demonstrate the connection to a local MySQL instance:

mysql> select @@hostname;
| @@hostname  |
| mycluster-0 |

Not seeing a port-forward to 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:

$> kubectl port-forward service/mycluster mysql
Forwarding from -> 6446
Forwarding from [::1]:3306 -> 6446

$> kubectl port-forward service/mycluster mysql-ro
Forwarding from -> 6447
Forwarding from [::1]:6447 -> 6447

A list of port names with their associated ports:

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.