Configurazione di MySQL come servizio fornito dall'utente
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questo documento descrive la procedura per associare la tua app a un'istanza MySQL non elencata nel marketplace di Kf (incluso Cloud SQL per MySQL) con il connettore Spring Cloud Foundry. Di conseguenza, le credenziali MySQL vengono iniettate nell'app, proprio come l'associazione ai servizi di cui è stato eseguito il provisioning tramite i piani del marketplace.
Prima di iniziare
Assicurati che MySQL sia installato e accessibile dal tuo cluster Kf.
Assicurati che il database per la tua app sia già stato creato.
Assicurati di avere scelto come target lo spazio in cui è in esecuzione la tua app.
Crea l'istanza fornita dall'utente
Affinché Kf possa associare correttamente un'app all'istanza MySQL, la variabile di ambiente minima è l'URI (ad esempio mysql://username:password@host:port/dbname). Se vuoi, puoi includere altre coppie chiave-valore. La documentazione di MySQL può aiutarti a creare una stringa URI. L'esempio seguente dovrebbe essere sufficiente per i deployment di base.
Puoi verificare le nuove variabili di ambiente fornite alla tua app:
kfvcap-servicesapplication-name
Aggiorna l'istanza fornita dall'utente
Se vengono apportate modifiche all'ambiente (ad esempio l'aggiornamento della password o dell'host nell'URI o l'aggiunta di nuove coppie chiave-valore) che devono essere trasmesse a qualsiasi app associata, puoi aggiornare l'istanza fornita dall'utente.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],null,["# Setting Up MySQL as a User-Provided Service\n\n| **Note:** You can leverage services that aren't listed in the marketplace by creating user-provided service instances that an App can bind to. Learn more about [user-provided services](../concepts/user-provided-services).\n\nThis document guides you through binding your App to a MySQL instance not listed in the Kf marketplace (including [Cloud SQL for MySQL](/sql)) 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.\n\nBefore you begin\n================\n\n- Ensure you have MySQL installed and accessible by your Kf cluster.\n- Ensure the database for your App has already been created.\n- Ensure you have targeted the Space running your App.\n\nCreate the user-provided instance\n=================================\n\nFor 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](https://dev.mysql.com/doc/refman/8.0/en/connecting-using-uri-or-key-value-pairs.html) can help with creating a URI string. The following example should be sufficient for basic deployments. \n\n kf cups \u003cvar translate=\"no\"\u003eservice-instance-name\u003c/var\u003e -p '{\"username\":\"\u003cvar translate=\"no\"\u003eusername\u003c/var\u003e\", \"password\":\"\u003cvar translate=\"no\"\u003epassword\u003c/var\u003e\", \"uri\":\"mysql://\u003cvar translate=\"no\"\u003eusername\u003c/var\u003e:\u003cvar translate=\"no\"\u003epassword\u003c/var\u003e@\u003cvar translate=\"no\"\u003emysql-host\u003c/var\u003e:\u003cvar translate=\"no\"\u003e3306\u003c/var\u003e/\u003cvar translate=\"no\"\u003edatabase\u003c/var\u003e\"}' -t \"mysql\"\n\nBind your App\n=============\n\nNow that the user-provided service has been created, you can bind your App to the instance name: \n\n kf bind-service \u003cvar translate=\"no\"\u003eapplication-name\u003c/var\u003e \u003cvar translate=\"no\"\u003eservice-instance-name\u003c/var\u003e\n\nRestart your App to for the changes to take effect: \n\n kf restart \u003cvar translate=\"no\"\u003eapplication-name\u003c/var\u003e\n\nYou can confirm the new environment variables being provided to your App: \n\n kf vcap-services \u003cvar translate=\"no\"\u003eapplication-name\u003c/var\u003e\n\nUpdate the user-provided instance\n=================================\n\nIf 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. \n\n kf uups \u003cvar translate=\"no\"\u003eservice-instance-name\u003c/var\u003e -p '{\"uri\":\"\u003cvar translate=\"no\"\u003enew-uri\u003c/var\u003e\", \"\u003cvar translate=\"no\"\u003esome-new-key\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003esome-new-value\u003c/var\u003e\"}'\n\n**Note:** After updating environment the service, you must unbind then rebind the service to make the changes active in your App. \n\n kf unbind-service \u003cvar translate=\"no\"\u003eapplication-name\u003c/var\u003e \u003cvar translate=\"no\"\u003eservice-instance-name\u003c/var\u003e\n kf bind-service \u003cvar translate=\"no\"\u003eapplication-name\u003c/var\u003e \u003cvar translate=\"no\"\u003eservice-instance-name\u003c/var\u003e\n\nRelated documents\n=================\n\n- [VCAP_SERVICES](/migrate/kf/docs/2.2/how-to/app-runtime#vcapservices)\n- [Unbind service](../cli/kf-unbind-service)\n- [Delete service](../cli/kf-delete-service)"]]