This topic provides instructions for developers using the VMware SQL with MySQL for Tanzu Application Service service for their VMware Tanzu Application Service for VMs apps.
VMware Tanzu for MySQL provides a relational database for apps and devices. To use VMware Tanzu for MySQL in an app:
Check the service availability in the Marketplace, and see if there is an existing instance of VMware Tanzu for MySQL in your space.
See Confirm the VMware Tanzu for MySQL service availability.
If there is no existing instance or you want to use a different one, create an instance of the VMware Tanzu for MySQL service in the same space as the app.
Bind the app to the VMware Tanzu for MySQL service instance, to enable the app to use MySQL.
Call the VMware Tanzu for MySQL service in your app code, and then push your app again into the space.
For more information on services, see Use the MySQL service in your app.
After you create a VMware Tanzu for MySQL service instance, you can manage it over the life cycle of your apps and data.
For more information on managing services instances, see Manage service instances.
The following procedures use the Cloud Foundry Command Line Interface (cf CLI).
For more information, see Managing service instances with the cf CLI. You can also use Apps Manager to do the same tasks using a graphical UI.
For more information, see Managing apps and service instances using Apps Manager
To use VMware Tanzu for MySQL with your TAS for VMs apps, you must:
For an app to use the VMware Tanzu for MySQL service, both of the following must be true:
You can confirm both of these using the cf CLI as follows.
To find out if a VMware Tanzu for MySQL service is available in the Marketplace:
Enter the following command:
cf marketplace
If the output lists p.mysql
in the service
column, VMware Tanzu for MySQL is available. If it is not available, ask your operator to install it.
$ cf marketplace
Getting services from marketplace in org my-org / space my-space as user@example.com...
OK
service plans description
[...]
p.mysql db-small Dedicated instances of MySQL service to provide a relational database
[...]
To confirm that a VMware Tanzu for MySQL instance is running in the space:
Enter the following command:
cf services
Any p.mysql
listings in the service
column are service instances of VMware Tanzu for MySQL in the space.
For example:
$ cf services
Getting services in org my-org / space my-space as user@example.com...
OK
name service plan bound apps last operation
my-instance p.mysql db-small create succeeded
You can bind your app to an existing instance or create a new instance to bind to your app.
On-demand services are created asynchronously, not immediately. The watch
command shows you when your service instance is ready to bind and use.
If you are deploying a leader-follower service instance across multiple foundations, follow the procedure in Using VMware Tanzu for MySQL for Multi‑Site Replication.
To create an instance of the VMware Tanzu for MySQL service:
Create a service instance by running the following command:
cf create-service p.mysql PLAN SERVICE-INSTANCE
Where:
PLAN
is the name of the VMware Tanzu for MySQL plan you want to use.SERVICE-INSTANCE
is a name you choose to identify the service instance. This name appears under service
in output from cf services
.Enter the following command and wait for the last operation
for your instance to show as create succeeded
.
watch cf services
For example:
$ cf create-service p.mysql db-small my-instance
Creating service my-instance in org my-org / space my-space as user@example.com... OK
$ watch cf services
Getting services in org my-org / space my-space as user@example.com... OK name service plan bound apps last operation my-instance p.mysql db-small create succeeded
If you get an error, see Troubleshooting instances.
For an app to use a service, you must bind the app to a service instance. You must do this after every time you run cf push
.
To push and bind an app to a VMware Tanzu for MySQL instance run the following command:
Push your app into the same space as your VMware Tanzu for MySQL service instance by running the following command:
cf push
Bind your app to a VMware Tanzu for MySQL instance by running the following command:
cf bind-service APP SERVICE-INSTANCE
Where:
APP
is the app you want to use the MySQL service instance.SERVICE-INSTANCE
is the name you supplied when you ran cf create-service
.For example:
$ cf bind-service my-app my-instance
Binding service mydb to my-app in org my-org / space test as user@example.com... OK TIP: Use 'cf push' to ensure your env variable changes take effect
Restart your app by running the following command:
cf restart APP
Where APP
is the app you want to use the MySQL service instance.
To access the MySQL service from your app:
Verify that your app code (or the MySQL client library that the app uses) retries in the case of DNS timeouts.
Locate the connection strings listed in the VCAP_SERVICES
> credentials
object for your app. For information about VCAP_SERVICES
, see MySQL environment variables.
In your app code, call the MySQL service using the connection strings.
See this example: Node.js code.
VMware Tanzu for MySQL supports multiple custom schemas. You can use custom schemas with apps that share a MySQL service instance to isolate app data by schema. By default, service bindings use the default schema service_instance_db
.
To use custom schemas in your apps:
Bind your app to the custom schema by running:
cf bind-service APP SERVICE-INSTANCE -c '{"schema":"CUSTOM-SCHEMA"}'
Where:
APP
is the app you want to use the custom schema.SERVICE-INSTANCE
is the name of your service instance.CUSTOM-SCHEMA
is the name of your custom schema. Valid characters include uppercase and lowercase letters, digits, $
, and _
.Restart your app by running:
cf restart APP
Where APP
is the app you want to use the custom schema.
Apps running in Ops Manager gain access to bound service instances through an environment variable credentials hash called VCAP_SERVICES
. This environment variable includes the credentials that apps use to access service instances.
For example:
{
"p.mysql": [
{
"label": "p.mysql",
"name": "my-instance",
"plan": "db-medium",
"provider": null,
"syslog_drain_url": null,
"tags": [
"mysql"
],
"credentials": {
"hostname": "10.0.0.20",
"jdbcUrl": "jdbc:mysql://10.0.0.20:3306/service_instance_db?user=fefcbe8360854a18a7994b870e7b0bf5\u0026password=z9z6eskdbs1rhtxt",
"name": "service_instance_db",
"password": "z9z6eskdbs1rhtxt",
"port": 3306,
"uri": "mysql://fefcbe8360854a18a7994b870e7b0bf5:[email protected]:3306/service_instance_db?reconnect=true",
"username": "fefcbe8360854a18a7994b870e7b0bf5"
},
"volume_mounts": []
}
]
}
You can search for your service by the name
given when the service instance was created. You can also search using the tags
or label
properties. The credentials
property can be used to provide access to the MySQL protocol.
VCAP_SERVICES
is only modified when an app is bound to a service instance. If you modify your service instance, you must cf unbind-service
, cf bind-service
and cf restage
your app to apply the changes to VCAP_SERVICES
.
If you use MySQL Connector/J 8.0.13 or later with VMware Tanzu for MySQL, you must modify the JDBC URL in VCAP_SERVICES
to include sslMode=VERIFY_IDENTITY
and verifyServerCertificate=true
. MySQL Connector/J 8.0.13 and later does not verify TLS connections. For more information about JDBC URL syntax, see the MySQL documentation.
If a developer rebinds an app to the VMware Tanzu for MySQL service after unbinding, they must also rebind any existing custom schemas to the app. When you rebind an app, stored code, programs, and triggers break. For more information about binding custom schemas, see Use custom schemas.
You can manage service instances in the following ways:
You can use cf update-service
to migrate data to a different plan. When you update a service instance, you do not need to rebind your app or service keys. However, when you migrate data to a new service instance the database is unavailable for several minutes.
For more information about using cf update-service
, see the Cloud Foundry CLI Reference Guide.
The following table lists migration use cases for the update-service
command:
Use update-service for migrating from... |
To... |
---|---|
Single Node | larger Single Node |
Leader-Follower | larger Leader-Follower |
Single Node | Leader-Follower of the same or larger size |
Leader-Follower | Single Node of the same or larger size |
High Availability | Multi‑Site Replication |
Multi‑Site Replication | High Availability |
You can only us cf update-service
to migrate data between an HA cluster plan and a multi‑site replication plan. If you want to do this with another plan, you must use the cf mysql-tools
plug-in instead. For more information about migrating data, see About data migration in VMware SQL with MySQL for Tanzu Application Service.
If a multi‑site replication is being used, it can only be updated to a HA Cluster plan. If a multi‑site replication is updated with any other plan besides an HA Cluster plan, replication will break.
To migrate a service instance to another plan:
View the available service plans for VMware Tanzu for MySQL by running:
cf marketplace
Migrate data to another plan by running:
cf update-service SERVICE-INSTANCE -p PLAN
Where PLAN
is the plan you want to update the service instance to.
For example:
$ cf update-service my-instance -p db-large
Before you individually upgrade service instances you must have cf CLI v6.46.0 or later.
You can use cf update-service
with the –upgrade
flag to individually upgrade on-demand service instances to the latest version of VMware Tanzu for MySQL. When you upgrade a service instance, you do not need to rebind your app or service keys. However, when you upgrade a service instance the database is unavailable for several minutes.
For more information about using cf update-service
, see the Cloud Foundry CLI Reference Guide.
To upgrade a single service instance:
Confirm that an upgrade is available for the service instance by running:
cf services
The upgrade is available when the upgrade available
column in the output says yes
.
For example:
$ cf services
Getting services in org system / space system as admin...
name service plan bound apps last operation broker upgrade available
my-instance p.mysql db-small create succeeded dedicated-mysql-broker yes
Upgrade the service instance by running:
cf update-service SERVICE-INSTANCE-NAME --upgrade
When you are prompted, confirm that you want to upgrade.
As of VMware Tanzu for MySQL v3.2, only MySQL 8.0 is supported. If you created a service instance using a previous version of VMware Tanzu for MySQL, then upgrading the service instance forces an upgrade to MySQL 8.0.
To upgrade a service instance, run the following command:
cf update-service SERVICE-INSTANCE-NAME --upgrade
Where SERVICE-INSTANCE-NAME
is the name of the service instance to upgrade.
The MySQL 8.0 version of the plan is applied to the service instance, triggering the service instance upgrade from 5.7 to 8.0.
ImportantWhen upgrading a highly available (HA) cluster from MySQL 5.7 to MySQL 8.0, VMware recommends that you first validate the HA cluster’s health. To verify that your HA cluster is healthy, see Monitoring Node Health. (A “highly available (HA) cluster” refers to any service instance created from a tile plan configured with the “HA cluster” topology.) If the HA cluster is unhealthy, bring the cluster to a healthy state before upgrading the cluster to MySQL 8.0.
In VMware Tanzu for MySQL you can share service instances between different orgs and spaces using cf share-service
. Service instance sharing is enabled by default.
For more information about service instance sharing, see Sharing service instances.
To share a service instance:
Target the source org and space for the service instance you want to share by running:
cf target -o SOURCE-ORG -s SOURCE-SPACE
Where:
SOURCE-ORG
is the source org for your service instance.SOURCE-SPACE
is the source space for your service instance.Share your service instance to the destination org and space by running:
cf share-service SERVICE-INSTANCE -o DESTINATION-ORG -s DESTINATION-SPACE
Where:
SERVICE-INSTANCE
is the service instance you want to share.DESTINATION-ORG
is the destination org for the service instance.DESTINATION-SPACE
is the destination space for the service instance.Target the destination org and space by running:
cf target -o DESTINATION-ORG -s DESTINATION-SPACE
Confirm the service instance was shared by running:
cf service SERVICE-INSTANCE
Where SERVICE-INSTANCE
is the service instance you shared.
If you want stop an app from using a service you must unbind the app from the service.
Unbind your app by running:
cf unbind-service APP SERVICE-INSTANCE
Where:
APP
is the app you want to stop using the MySQL service instance.SERVICE-INSTANCE
is the name you supplied when you ran cf create-service
.For example:
$ cf unbind-service my-app my-instance
Unbinding app my-app from service my-instance in org my-org / space my-space as user@example.com... OK
If a developer rebinds an app to the VMware Tanzu for MySQL service after unbinding, they must also rebind any existing custom schemas to the app. When you rebind an app, stored code, programs, and triggers break. For more information about binding custom schemas, see Use custom schemas.
You cannot delete a service instance that an app is bound to.
To delete a service instance:
Run the following command:
cf delete-service SERVICE-INSTANCE
Where SERVICE-INSTANCE
is the name of the service to delete.
For example:
$ cf delete-service my-instance
Are you sure you want to delete the service my-instance ? y Deleting service my-service in org my-org / space my-space as user@example.com... OK
Enter the following command and wait for a Service instance not found
error indicating that the instance no longer exists:
watch cf service SERVICE-INSTANCE
If the service instance VM is lost, then you cannot delete the service instance. However, you can use the cf CLI to purge a service instance from the Cloud Controller database.
To purge a service instance:
Run:
cf purge-service-instance SERVICE-INSTANCE-NAME
Where SERVICE-INSTANCE-NAME
is the name of the service instance to purge.
For example:
$ cf purge-service-instance my-instance
WARNING: This operation assumes that the service broker responsible for this service instance is no longer available or is not responding with a 200 or 410, and the service instance has been deleted, leaving orphan records in Cloud Foundry's database. All knowledge of the service instance are removed from Cloud Foundry, including service bindings and service keys. Really purge service instance my-instance from Cloud Foundry?> y Purging service my-instance... OK