Establishing a Connection from Outside a Deployment
Page last updated:
This topic provides instructions for developers for establishing a connection to a VMware Tanzu SQL with MySQL for VMs service instance from outside your deployment.
Overview
If you want to connect to a MySQL service instance from outside the VMware Tanzu Application Service for VMs deployment where your Tanzu SQL for VMs service instance is located, you can do one of the following:
You may want to use an SSH tunnel or IP address for establishing a connection in the following cases:
- Connecting from a local workstation. For more information, see Tanzu SQL for VMs Tools.
- Connecting from outside where your Tanzu SQL for VMs service instance is located.
- Connecting from a legacy app that is not in your TAS for VMs deployment.
- Taking a manual backup to be stored locally. For more information, see Backing Up and Restoring with mysqldump.
Connect Using an SSH Tunnel
Any app deployed within your deployment can resolve BOSH DNS hostnames and forward traffic to MySQL service instances using an SSH tunnel.
Prerequisite
To connect using an SSH tunnel, you must have SSH access to app containers. For more information, see Configuring SSH Access for TAS for VMs.
Procedure
To connect to a MySQL instance using an SSH tunnel, follow the procedures in Accessing Services with SSH
Connect Using an IP Address
You can also connect remotely to the MySQL service instance by directly using its IP address.
You can obtain the IP address using one the following methods:
Using cf SSH. For more information, see Obtain the IP Address Using cf SSH.
Using the DNS Lookup app. For more information, see Obtain the IP Address Using the DNS Lookup App.
Using the BOSH CLI. For more information, see Obtain the IP Address Using the BOSH CLI.
Note: By connecting to the MySQL service instance directly using its IP address, the client is responsible to handle cases in which the IP address of the service instance will change transparently. This can happen when a VM is recreated, or during a failover.
Obtain the IP Address Using cf SSH
If you have limited access to the platform you can obtain the IP address through cf SSH.
Prerequisites
To obtain the IP address using cf SSH, you must have the following:
SSH access to app containers. For more information, see Configuring SSH Access for TAS for VMs.
An app deployed on the same deployment as the MySQL service instance.
Procedure
To obtain the IP address using cf SSH, follow these steps:
To retrieve your service key, run the following command:
cf service-keys SERVICE-INSTANCE
Where
SERVICE-INSTANCE
is the name of your Tanzu SQL for VMs service instance.To obtain the BOSH DNS hostname of the MySQL service instance, run the following command:
cf service-key SERVICE-INSTANCE SERVICE-KEY
For example:
$ cf service-key my-mysql my-service-key Getting key my-service-key for service instance my-mysql as admin... { "hostname": "q-n1a2b3.q-c456.bosh", "jdbcUrl": "jdbc:mysql://10.10.10.5:3306/cf_e2d148a8_1baa_4961_b314_2431f57037e5?user=my_unique_name\u0026password=123456789", "name": "cf_e2d148a8_1baa_4961_b314_2431f57037e5", "password": "123456789", "port": 3306, "uri": "mysql://my_unique_name:123456789@10.10.10.5:3306/cf_e2d148a8_1baa_4961_b314_2431f57037e5?reconnect=true", "username": "myuser" }
Record the value of
hostname
.To SSH into the app, run the following command:
$ cf ssh APP-NAME
Where
APP-NAME
is the name of your app deployed on the same deployment as the MySQL service instance.To obtain the IP address of the service instance, run the following command:
$ dig +short BOSH-DNS-HOSTNAME
Where
BOSH-DNS-HOSTNAME
is the BOSH DNS hostname that you retrieved from step 2.The output of the command is the IP address.
Obtain the IP Address Using the DNS Lookup App
See the following screenshot of the DNS Lookup UI:
If your deployment has app SSH disabled, you can deploy the DNS Lookup app to your deployment. The DNS Lookup app resolves BOSH DNS hostnames.
For more information, see the dns-lookup repository in GitHub.
Obtain the IP Address Using the BOSH CLI
If you have access to the BOSH CLI, you can obtain the IP address through it.
Prerequisite
To connect using the BOSH CLI, you must have have access to the BOSH CLI. Ask your operator for access to the BOSH CLI.
Procedure
To connect using the BOSH CLI, follow these steps:
To obtain the credentials and IP address needed to use the BOSH CLI, follow the procedure in Gather Credential and IP Address Information.
To SSH into your Ops Manager VM, follow the procedure in Log in to the Ops Manager VM with SSH for your IaaS.
To log in to your BOSH Director, follow the procedure in Log in to the BOSH Director VM.
To obtain the MySQL service instance GUID, run the following command:
cf service SERVICE-INSTANCE --guid
Where
SERVICE-INSTANCE
is the name of your Tanzu SQL for VMs service instance.To use the BOSH CLI to view the IP address, run one of the following commands depending on your topology:
If your MySQL service instance topology is single node or highly available (HA) cluster, run the following command:
bosh -d service-instance_GUID instance
Where
GUID
is the GUID of the service instance retrieved above.If you are using an HA cluster, record the IP address of any of your instances.
For example:
$ bosh -d service-instance_b2e92d56-27e2-407e-90e0-c34612c10dba \ instances Using environment 'https://10.0.0.6:25555' as client 'admin'
Task 21409. Done
Deployment 'service-instance_0b26c8d1-2795-438e-bcbf-339e77daf88e'
Instance Process State AZ IPs mysql/1373022d-4eab-46d3-8fd1-a12067edf597 running z2 10.0.17.14
1 instances
Succeeded
If your MySQL service instance topology is leader-follower, run the following command:
bosh -d service-instance_GUID run-errand inspect
Record the IP address for the instance marked
Role: leader
.For example:
Instance mysql/ca0ed8b5-7590-4cde-bba8-7ca2935f2bd0 Exit Code 0 Stdout 2018/04/03 18:08:46 Started executing command: inspect 2018/04/03 18:08:46 IP Address: 10.0.8.11 Role: leader Read Only: false Replication Configured: false Replication Mode: async Has Data: true GTID Executed: 82ddc607-710a-404e-b1b8-a7e3ea7ec063:1-18 2018/04/03 18:08:46 Successfully executed command: inspect Stderr -
Instance mysql/37e4b6bc-2ed6-4bd2-84d1-e59a91f5e7f8 Exit Code 0 Stdout 2018/04/03 18:08:46 Started executing command: inspect 2018/04/03 18:08:46 IP Address: 10.0.8.10 Role: follower Read Only: true Replication Configured: true Replication Mode: async Has Data: true GTID Executed: 82ddc607-710a-404e-b1b8-a7e3ea7ec063:1-18 2018/04/03 18:08:46 Successfully executed command: inspect