Skip to content

Commit 9bbbaab

Browse files
authored
Merge pull request #209323 from maud-lv/ml-spring-mysql2
Update MySQL quickstart with Service Connector
2 parents d122939 + e302003 commit 9bbbaab

File tree

4 files changed

+101
-132
lines changed

4 files changed

+101
-132
lines changed
33.1 KB
Loading
14.5 KB
Loading
85.8 KB
Loading

articles/spring-apps/quickstart-integrate-azure-database-mysql.md

Lines changed: 101 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: "Quickstart - Integrate with Azure Database for MySQL"
33
description: Explains how to provision and prepare an Azure Database for MySQL instance, and then configure Pet Clinic on Azure Spring Apps to use it as a persistent database with only one command.
4-
author: karlerickson
5-
ms.author: karler
4+
author: maud-lv
5+
ms.author: malev
66
ms.service: spring-apps
77
ms.topic: quickstart
8-
ms.date: 10/15/2021
9-
ms.custom: devx-track-java, devx-track-azurecli, mode-other, event-tier1-build-2022
8+
ms.date: 08/28/2022
9+
ms.custom: devx-track-java, devx-track-azurecli, mode-other, event-tier1-build-2022, service-connector
1010
---
1111

1212
# Quickstart: Integrate Azure Spring Apps with Azure Database for MySQL
@@ -20,172 +20,141 @@ Pet Clinic, as deployed in the default configuration [Quickstart: Build and depl
2020

2121
## Prerequisites
2222

23-
* [MySQL CLI is installed](http://dev.mysql.com/downloads/mysql/)
24-
25-
## Variables preparation
26-
27-
We will use the following values. Save them in a text file or environment variables to avoid errors. The password should be at least 8 characters long and contain at least one English uppercase letter, one English lowercase letter, one number, and one non-alphanumeric character (!, $, #, %, and so on.).
28-
29-
```bash
30-
export RESOURCE_GROUP=<resource-group-name> # customize this
31-
export MYSQL_SERVER_NAME=<mysql-server-name> # customize this
32-
export MYSQL_SERVER_FULL_NAME=${MYSQL_SERVER_NAME}.mysql.database.azure.com
33-
export MYSQL_SERVER_ADMIN_NAME=<admin-name> # customize this
34-
export MYSQL_SERVER_ADMIN_LOGIN_NAME=${MYSQL_SERVER_ADMIN_NAME}\@${MYSQL_SERVER_NAME}
35-
export MYSQL_SERVER_ADMIN_PASSWORD=<password> # customize this
36-
export MYSQL_DATABASE_NAME=petclinic
37-
```
23+
An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free).
3824

3925
## Prepare an Azure Database for MySQL instance
4026

41-
1. If you didn't run the following commands in the previous quickstarts, set the CLI defaults.
27+
1. Create an Azure Database for MySQL flexible server using the [az mysql flexible-server create](/cli/azure/mysql/flexible-server#az-mysql-flexible-server-create) command. Replace the placeholders `<database-name>`, `<resource-group-name>`, `<MySQL-flexible-server-name>`, `<admin-username>`, and `<admin-password>` with a name for your new database, the name of your resource group, a name for your new server, and an admin username and password.
4228

43-
```azcli
44-
az configure --defaults group=<resource group name> spring-cloud=<service name>
29+
```azurecli-interactive
30+
az mysql flexible-server create \
31+
--resource-group <resource-group-name> \
32+
--name <MySQL-flexible-server-name> \
33+
--database-name <database-name> \
34+
--admin-user <admin-username> \
35+
--admin-password <admin-password>
4536
```
4637

47-
1. Create an Azure Database for MySQL server.
38+
> [!NOTE]
39+
> Standard_B1ms SKU is used by default. Refer to [Azure Database for MySQL pricing](https://azure.microsoft.com/pricing/details/mysql/flexible-server/) for pricing details.
4840
49-
```azcli
50-
az mysql server create --resource-group ${RESOURCE_GROUP} \
51-
--name ${MYSQL_SERVER_NAME} \
52-
--admin-user ${MYSQL_SERVER_ADMIN_NAME} \
53-
--admin-password ${MYSQL_SERVER_ADMIN_PASSWORD} \
54-
--sku-name GP_Gen5_2 \
55-
--ssl-enforcement Disabled \
56-
--version 5.7
57-
```
41+
> [!TIP]
42+
> Password should be at least eight characters long and contain at least one English uppercase letter, one English lowercase letter, one number, and one non-alphanumeric character (!, $, #, %, and so on.).
5843
59-
1. Allow access from Azure resources.
44+
1. A CLI prompt asks if you want to enable access to your IP. Enter `Y` to confirm.
6045

61-
```azcli
62-
az mysql server firewall-rule create --name allAzureIPs \
63-
--server ${MYSQL_SERVER_NAME} \
64-
--resource-group ${RESOURCE_GROUP} \
65-
--start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
66-
```
46+
## Connect your application to the MySQL database
6747

68-
1. Allow access from your dev machine for testing.
48+
Use [Service Connector](../service-connector/overview.md) to connect the app hosted in Azure Spring Apps to your MySQL database.
6949

70-
```azcli
71-
az mysql server firewall-rule create --name devMachine \
72-
--server ${MYSQL_SERVER_NAME} \
73-
--resource-group ${RESOURCE_GROUP} \
74-
--start-ip-address <ip-address-of-your-dev-machine> \
75-
--end-ip-address <ip-address-of-your-dev-machine>
76-
```
50+
> [!NOTE]
51+
> The service binding feature in Azure Spring Apps is being deprecated in favor of Service Connector.
7752
78-
1. Increase connection timeout.
53+
### [Azure CLI](#tab/azure-cli)
7954

80-
```azcli
81-
az mysql server configuration set --name wait_timeout \
82-
--resource-group ${RESOURCE_GROUP} \
83-
--server ${MYSQL_SERVER_NAME} --value 2147483
84-
```
55+
1. If you're using Service Connector for the first time, start by running the command [az provider register](/cli/azure/provider#az-provider-register) to register the Service Connector resource provider.
8556

86-
1. Create database in the MySQL server and set corresponding settings.
57+
```azurecli-interactive
58+
az provider register --namespace Microsoft.ServiceLinker
59+
```
8760
88-
```sql
89-
// SUBSTITUTE values
90-
mysql -u ${MYSQL_SERVER_ADMIN_LOGIN_NAME} \
91-
-h ${MYSQL_SERVER_FULL_NAME} -P 3306 -p
61+
1. Run the `az spring connection create` command to create a service connection between Azure Spring Apps and the Azure MySQL database. Replace the placeholders below with your own information.
9262
93-
Enter password:
94-
Welcome to the MySQL monitor. Commands end with ; or \g.
95-
Your MySQL connection id is 64379
96-
Server version: 5.6.39.0 MySQL Community Server (GPL)
63+
| Setting | Description |
64+
|---------------------------|----------------------------------------------------------------------------------------------|
65+
| `--resource-group` | The name of the resource group that contains the app hosted by Azure Spring Apps. |
66+
| `--service` | The name of the Azure Spring Apps resource. |
67+
| `--app` | The name of the application hosted by Azure Spring Apps that connects to the target service. |
68+
| `--target-resource-group` | The name of the resource group with the storage account. |
69+
| `--server` | The MySQL server you want to connect to |
70+
| `--database` | The name of the database you created earlier. |
71+
| `--secret name` | The MySQL server username. |
72+
| `--secret` | The MySQL server password. |
9773
98-
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
74+
```azurecli-interactive
75+
az spring connection create mysql-flexible \
76+
--resource-group <Azure-Spring-Apps-resource-group-name> \
77+
--service <Azure-Spring-Apps-resource-name> \
78+
--app <app-name> \
79+
--target-resource-group <mySQL-server-resource-group> \
80+
--server <server-name> \
81+
--database <database-name> \
82+
--secret name=<username> secret=<secret>
83+
```
9984
100-
Oracle is a registered trademark of Oracle Corporation and/or its
101-
affiliates. Other names may be trademarks of their respective
102-
owners.
85+
> [!TIP]
86+
> If the `az spring` command isn't recognized by the system, check that you have installed the Azure Spring Apps extension by running `az extension add --name spring`.
10387
104-
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
88+
### [Portal](#tab/azure-portal)
10589
106-
mysql> CREATE DATABASE petclinic;
107-
Query OK, 1 row affected (0.10 sec)
90+
1. In the Azure portal, type the name of your Azure Spring Apps instance in the search box at the top of the screen and select your instance.
91+
1. Under **Settings**, select **Apps** and select the application from the list.
92+
1. Select **Service Connector** from the left table of contents and select **Create**.
10893
109-
mysql> CREATE USER 'root' IDENTIFIED BY 'petclinic';
110-
Query OK, 0 rows affected (0.11 sec)
94+
:::image type="content" source="./media\quickstart-integrate-azure-database-mysql\create-service-connection.png" alt-text="Screenshot of the Azure portal, in the Azure Spring Apps instance, create a connection with Service Connector.":::
11195
112-
mysql> GRANT ALL PRIVILEGES ON petclinic.* TO 'root';
113-
Query OK, 0 rows affected (1.29 sec)
96+
1. Select or enter the following settings in the table.
11497
115-
mysql> CALL mysql.az_load_timezone();
116-
Query OK, 3179 rows affected, 1 warning (6.34 sec)
98+
| Setting | Example | Description |
99+
|---------------------------|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
100+
| **Service type** | *DB for MySQL flexible server* | Select DB for MySQL flexible server as your target service |
101+
| **Subscription** | *my-subscription* | The subscription that contains your target service. The default value is the subscription that contains the app deployed to Azure Spring Apps. |
102+
| **Connection name** | *mysql_rk29a* | The connection name that identifies the connection between your app and target service. Use the connection name provided by Service Connector or enter your own connection name. |
103+
| **MySQL flexible server** | *MySQL80* | Select the MySQL flexible server you want to connect to. |
104+
| **MySQL database** | *petclinic* | Select the database you created earlier. |
105+
| **Client type** | *.NET* | Select the application stack that works with the target service you selected. |
117106
118-
mysql> SELECT name FROM mysql.time_zone_name;
119-
...
107+
:::image type="content" source="./media\quickstart-integrate-azure-database-mysql\basics-tab.png" alt-text="Screenshot of the Azure portal, filling out the basics tab in Service Connector.":::
120108
121-
mysql> quit
122-
Bye
123-
```
109+
1. Select **Next: Authentication** to select the authentication type. Then select **Connection string > Database credentials** and enter your database username and password.
124110
125-
1. Set timezone.
111+
1. Select **Next: Networking** to select the network configuration and select **Configure firewall rules to enable access to target service**. Enter your username and password so that your app can reach the database.
126112
127-
```azcli
128-
az mysql server configuration set \
129-
--resource-group ${RESOURCE_GROUP} \
130-
--name time_zone \
131-
--server ${MYSQL_SERVER_NAME} \
132-
--value "US/Pacific"
133-
```
113+
1. Select **Next: Review + Create** to review the provided information. Wait a few seconds for Service Connector to validate the information and select **Create** to create the service connection.
134114
135-
## Update Apps to use MySQL database
115+
---
116+
117+
## Check connection to MySQL database
118+
119+
### [Azure CLI](#tab/azure-cli)
136120
137-
To enable MySQL as database for the sample app, simply update the *customer-service* app with active profile MySQL and database credentials as environment variables.
121+
Run the `az spring connection validate` command to show the status of the connection between Azure Spring Apps and the Azure MySQL database. Replace the placeholders below with your own information.
138122
139-
```azcli
140-
az spring app update \
141-
--name customers-service \
142-
--jvm-options="-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql" \
143-
--env \
144-
MYSQL_SERVER_FULL_NAME=${MYSQL_SERVER_FULL_NAME} \
145-
MYSQL_DATABASE_NAME=${MYSQL_DATABASE_NAME} \
146-
MYSQL_SERVER_ADMIN_LOGIN_NAME=${MYSQL_SERVER_ADMIN_LOGIN_NAME} \
147-
MYSQL_SERVER_ADMIN_PASSWORD=${MYSQL_SERVER_ADMIN_PASSWORD}
123+
```azurecli-interactive
124+
az spring connection validate
125+
--resource-group <Azure-Spring-Apps-resource-group-name> \
126+
--service <Azure-Spring-Apps-resource-name> \
127+
--app <app-name> \
128+
--connection <connection-name>
148129
```
149130

150-
## Update extra apps
151-
152-
```azcli
153-
az spring app update --name api-gateway \
154-
--jvm-options="-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql"
155-
az spring app update --name admin-server \
156-
--jvm-options="-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql"
157-
az spring app update --name customers-service \
158-
--jvm-options="-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql" \
159-
--env \
160-
MYSQL_SERVER_FULL_NAME=${MYSQL_SERVER_FULL_NAME} \
161-
MYSQL_DATABASE_NAME=${MYSQL_DATABASE_NAME} \
162-
MYSQL_SERVER_ADMIN_LOGIN_NAME=${MYSQL_SERVER_ADMIN_LOGIN_NAME} \
163-
MYSQL_SERVER_ADMIN_PASSWORD=${MYSQL_SERVER_ADMIN_PASSWORD}
164-
az spring app update --name vets-service \
165-
--jvm-options="-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql" \
166-
--env \
167-
MYSQL_SERVER_FULL_NAME=${MYSQL_SERVER_FULL_NAME} \
168-
MYSQL_DATABASE_NAME=${MYSQL_DATABASE_NAME} \
169-
MYSQL_SERVER_ADMIN_LOGIN_NAME=${MYSQL_SERVER_ADMIN_LOGIN_NAME} \
170-
MYSQL_SERVER_ADMIN_PASSWORD=${MYSQL_SERVER_ADMIN_PASSWORD}
171-
az spring app update --name visits-service \
172-
--jvm-options="-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql" \
173-
--env \
174-
MYSQL_SERVER_FULL_NAME=${MYSQL_SERVER_FULL_NAME} \
175-
MYSQL_DATABASE_NAME=${MYSQL_DATABASE_NAME} \
176-
MYSQL_SERVER_ADMIN_LOGIN_NAME=${MYSQL_SERVER_ADMIN_LOGIN_NAME} \
177-
MYSQL_SERVER_ADMIN_PASSWORD=${MYSQL_SERVER_ADMIN_PASSWORD}
131+
The following output is displayed:
132+
133+
```Output
134+
Name Result
135+
------------------------------------------------------------- --------
136+
The target existence is validated success
137+
The target service firewall is validated success
138+
The configured values (except username/password) is validated success
178139
```
179140

141+
> [!TIP]
142+
> To get more details about the connection between your services, remove `--output table` from the above command.
143+
144+
### [Portal](#tab/azure-portal)
145+
146+
Azure Spring Apps connections are displayed under **Settings > Service Connector**. Select **Validate** to check your connection status, and select **Learn more** to review the connection validation details.
147+
148+
:::image type="content" source="./media\quickstart-integrate-azure-database-mysql\check-connection.png" alt-text="Screenshot of the Azure portal, in the Azure Spring Apps instance, check connection to MySQL database.":::
149+
150+
---
151+
180152
## Clean up resources
181153

182-
If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When no longer needed, delete the resource group, which deletes the resources in the resource group. To delete the resource group by using Azure CLI, use the following commands:
154+
If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. When no longer needed, delete the resource group by using the [az group delete](/cli/azure/group#az-group-delete) command, which deletes the resources in the resource group. Replace `<resource-group>` with the name of your resource group.
183155

184156
```azurecli
185-
echo "Enter the Resource Group name:" &&
186-
read resourceGroupName &&
187-
az group delete --name $resourceGroupName &&
188-
echo "Press [ENTER] to continue ..."
157+
az group delete --name <resource-group>
189158
```
190159

191160
## Next steps

0 commit comments

Comments
 (0)