This document guides you through binding your App to a MySQL instance not listed in the Kf marketplace (including Cloud SQL for MySQL) with the Spring Cloud Foundry Connector. This results in the MySQL credentials being injected into the App, just like binding to services provisioned through marketplace plans.
Before you begin
- Ensure you have MySQL installed and accessible by your Kf cluster.
- Ensure the database for your App has already been created.
- Ensure you have targeted the Space running your App.
Create the user-provided instance
For Kf to successfully bind an App to your MySQL instance, the minimum environment variable is the URI (for example mysql://username:password@host:port/dbname
). Additional key-value pairs may be included if desired. The MySQL documentation can help with creating a URI string. The following example should be sufficient for basic deployments.
kf cups service-instance-name -p '{"username":"username", "password":"password", "uri":"mysql://username:password@mysql-host:3306/database"}' -t "mysql"
Bind your App
Now that the user-provided service has been created, you can bind your App to the instance name:
kf bind-service application-name service-instance-name
Restart your App to for the changes to take effect:
kf restart application-name
You can confirm the new environment variables being provided to your App:
kf vcap-services application-name
Update the user-provided instance
If there are changes to the environment (for example password or host update in the URI, or the addition of new key-value pairs) that need to be passed on to any App bound to it, you can update the user-provided instance.
kf uups service-instance-name -p '{"uri":"new-uri", "some-new-key": "some-new-value"}'