Tutorial: Deploy an application to Azure Spring Apps and connect it to Azure Database for MySQL Flexible Server using Service Connector
Artikkel
In this tutorial, you'll complete the following tasks using the Azure portal or the Azure CLI. Both methods are explained in the following procedures.
Provision an instance of Azure Spring Apps
Build and deploy apps to Azure Spring Apps
Integrate Azure Spring Apps with Azure Database for MySQL with Service Connector
Advarsel
Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a very high degree of trust in the application, and carries risks that are not present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable.
The following procedure uses the Azure CLI extension to provision an instance of Azure Spring Apps.
Update Azure CLI with the Azure Spring Apps extension.
Azure CLI
az extension update --name spring
Sign in to the Azure CLI and choose your active subscription.
Azure CLI
az loginaz account list -o table
az account set --subscription<Name or ID of subscription, skip if you only have 1 subscription>
Create a resource group to contain your app and an instance of the Azure Spring Apps service.
Azure CLI
az group create --name ServiceConnector-tutorial-mysqlf--location eastus
Create an instance of Azure Spring Apps. Its name must be between 4 and 32 characters long and can only contain lowercase letters, numbers, and hyphens. The first character of the Azure Spring Apps instance name must be a letter and the last character must be either a letter or a number.
Azure CLI
az spring create -n my-azure-spring-g ServiceConnector-tutorial-mysqlf
Create an Azure Database for MySQL Flexible Server
Create a MySQL Flexible Server instance. In the command below, replace <admin-username> and <admin-password> by credentials of your choice to create an administrator user for the MySQL flexible server. The admin username can't be azure_superuser, azure_pg_admin, admin, administrator, root, guest, or public. It can't start with pg_. The password must contain 8 to 128 characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters (for example, !, #, %). The password can't contain username.
Azure CLI
az mysql flexible-server create \
--resource-group ServiceConnector-tutorial-mysqlf \
--name mysqlf-server \
--database-name mysqlf-db \
--admin-user<admin-username> \
--admin-password<admin-password>
The server is created with the following default values unless you manually override them:
Setting
Default value
Description
server-name
System generated
A unique name that identifies your Azure Database for MySQL server.
sku-name
GP_Gen5_2
The name of the sku. Follows the convention {pricing tier}_{compute generation}_{vCores} in shorthand. The default is a General Purpose Gen5 server with 2 vCores. For more information about the pricing, go to our pricing page.
backup-retention
7
How long a backup should be retained. Unit is days.
geo-redundant-backup
Disabled
Whether geo-redundant backups should be enabled for this server or not.
location
westus2
The Azure location for the server.
ssl-enforcement
Enabled
Whether SSL should be enabled or not for this server.
storage-size
5120
The storage capacity of the server (unit is megabytes).
For more information about the az mysql flexible-server create command and its additional parameters, see the Azure CLI documentation.
Build and deploy the app
Create the app with public endpoint assigned. If you selected Java version 11 when generating the Azure Spring Apps project, include the --runtime-version=Java_11 switch.
Azure CLI
az spring app create -n hellospring -s my-azure-spring-g ServiceConnector-tutorial-mysqlf--assign-endpointtrue
Run the az spring connection create command to connect the application deployed to Azure Spring Apps to the MySQL Flexible Server database. Replace the placeholders below with your own information.
The name of the resource group that contains the app hosted by Azure Spring Apps.
--service
The name of the Azure Spring Apps resource.
--app
The name of the application hosted by Azure Spring Apps that connects to the target service.
--target-resource-group
The name of the resource group with the storage account.
--server
The MySQL Flexible Server you want to connect to
--database
The name of the database you created earlier.
--secret name
The MySQL Flexible Server username.
--secret
The MySQL Flexible Server password.
Obs!
If you see the error message "The subscription is not registered to use Microsoft.ServiceLinker", please run az provider register -n Microsoft.ServiceLinker to register the Service Connector resource provider and run the connection command again.
Administrer en SQL Server-databaseinfrastruktur for skybaserte, lokale og hybride relasjonsdatabaser ved hjelp av microsoft PaaS-relasjonsdatabasetilbud.