Skip to content

Commit 0d5efe6

Browse files
author
Jill Grant
authored
Merge pull request #243035 from moarychan/moary/tutorial/improve-business-logic
Improve business logic when integrating with MySQL
2 parents 571ecda + f8a1706 commit 0d5efe6

File tree

2 files changed

+63
-23
lines changed

2 files changed

+63
-23
lines changed
46.3 KB
Loading

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

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ ms.custom: devx-track-java, devx-track-extended-java, devx-track-azurecli, mode-
1616
1717
**This article applies to:** ✔️ Basic/Standard ❌ Enterprise
1818

19-
Pet Clinic, as deployed in the default configuration [Quickstart: Build and deploy apps to Azure Spring Apps](quickstart-deploy-apps.md), uses an in-memory database (HSQLDB) that is populated with data at startup. This quickstart 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.
19+
Pet Clinic, as deployed in the default configuration [Quickstart: Build and deploy apps to Azure Spring Apps](./quickstart-deploy-apps.md), uses an in-memory database (HSQLDB) that is populated with data at startup. This quickstart 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.
2020

2121
## Prerequisites
2222

2323
An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free).
2424

25-
## Prepare an Azure Database for MySQL instance
25+
## Create an Azure Database for MySQL instance
2626

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. Use single quotes around the value for `admin-password`.
27+
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. Use single quotes around the value for `admin-password`.
2828

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-
--public-access 0.0.0.0 \
35-
--admin-user <admin-username> \
36-
--admin-password '<admin-password>'
37-
```
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+
--public-access 0.0.0.0 \
35+
--admin-user <admin-username> \
36+
--admin-password '<admin-password>'
37+
```
3838

39-
> [!NOTE]
40-
> The `Standard_B1ms` SKU is used by default. For pricing details, see [Azure Database for MySQL pricing](https://azure.microsoft.com/pricing/details/mysql/flexible-server/).
39+
> [!NOTE]
40+
> The `Standard_B1ms` SKU is used by default. For pricing details, see [Azure Database for MySQL pricing](https://azure.microsoft.com/pricing/details/mysql/flexible-server/).
4141
42-
> [!TIP]
43-
> The 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.).
42+
> [!TIP]
43+
> The 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.).
4444
4545
## Connect your application to the MySQL database
4646

@@ -57,7 +57,7 @@ Use [Service Connector](../service-connector/overview.md) to connect the app hos
5757
az provider register --namespace Microsoft.ServiceLinker
5858
```
5959

60-
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. Use single quotes around the value for MySQL server `secret`.
60+
1. Run the `az spring connection create` command to create a service connection between the `customers-service` app and the Azure MySQL database. Replace the placeholders for the following settings with your own information. Use single quotes around the value for MySQL server `secret`.
6161

6262
| Setting | Description |
6363
|---------------------------|------------------------------------------------------------------------------------------------|
@@ -74,7 +74,7 @@ Use [Service Connector](../service-connector/overview.md) to connect the app hos
7474
az spring connection create mysql-flexible \
7575
--resource-group <Azure-Spring-Apps-resource-group-name> \
7676
--service <Azure-Spring-Apps-resource-name> \
77-
--app <app-name> \
77+
--app customers-service \
7878
--connection <mysql-connection-name-for-app> \
7979
--target-resource-group <mySQL-server-resource-group> \
8080
--server <server-name> \
@@ -85,10 +85,10 @@ Use [Service Connector](../service-connector/overview.md) to connect the app hos
8585
> [!TIP]
8686
> 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`.
8787
88-
### [Portal](#tab/azure-portal)
88+
### [Azure portal](#tab/azure-portal)
8989

9090
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.
91+
1. Under **Settings**, select **Apps**, and then select the `customers-service` application from the list.
9292
1. Select **Service Connector** from the left table of contents and select **Create**.
9393

9494
:::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.":::
@@ -114,17 +114,19 @@ Use [Service Connector](../service-connector/overview.md) to connect the app hos
114114

115115
---
116116

117+
Repeat these steps to create connections for the `customers-service`, `vets-service`, and `visits-service` applications.
118+
117119
## Check connection to MySQL database
118120

119121
### [Azure CLI](#tab/azure-cli)
120122

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.
123+
Run the `az spring connection validate` command to show the status of the connection between the `customers-service` app and the Azure MySQL database. Replace the placeholders with your own information.
122124

123125
```azurecli-interactive
124126
az spring connection validate \
125127
--resource-group <Azure-Spring-Apps-resource-group-name> \
126128
--service <Azure-Spring-Apps-resource-name> \
127-
--app <app-name> \
129+
--app customers-service \
128130
--connection <mysql-connection-name-for-app> \
129131
--output table
130132
```
@@ -150,6 +152,44 @@ Azure Spring Apps connections are displayed under **Settings > Service Connector
150152

151153
---
152154

155+
Repeat these instructions to validate the connections for the `customers-service`, `vets-service`, and `visits-service` applications.
156+
157+
## Update apps to use MySQL profile
158+
159+
The following section explains how to update the apps to connect to the MySQL database.
160+
161+
### [Azure CLI](#tab/azure-cli)
162+
163+
Use the following command to set an environment variable to activate the `mysql` profile for the `customers-service` app:
164+
165+
```azurecli
166+
az spring app update \
167+
--resource-group <Azure-Spring-Apps-resource-group-name> \
168+
--service <Azure-Spring-Apps-resource-name> \
169+
--name customers-service \
170+
--env SPRING_PROFILES_ACTIVE=mysql
171+
```
172+
173+
### [Azure portal](#tab/azure-portal)
174+
175+
Use the following steps to set an environment variable to activate the `mysql` profile for the `customers-service` app:
176+
177+
1. Go to the Azure Spring Apps instance overview page, select **Apps** from the navigation menu, and then select the **customers-service** application from the list.
178+
179+
1. On the **customers-service Overview** page, select **Configuration** from the navigation menu.
180+
181+
1. On the **Configuration** page, select **Environment variables**. Enter `SPRING_PROFILES_ACTIVE` for **Key**, enter `mysql` for **Value**, and then select **Save**.
182+
183+
:::image type="content" source="media/quickstart-integrate-azure-database-mysql/customers-service-app-configuration.png" alt-text="Screenshot of the Azure portal showing the configuration settings for the customers-service app." lightbox="media/quickstart-integrate-azure-database-mysql/customers-service-app-configuration.png":::
184+
185+
---
186+
187+
Repeat these instructions to update app configuration for the `customers-service`, `vets-service`, and `visits-service` applications.
188+
189+
## Validate the apps
190+
191+
To validate the Pet Clinic service and to query records from the MySQL database to confirm the database connection, follow the instructions in the [Verify the services](./quickstart-deploy-apps.md?pivots=programming-language-java#verify-the-services) section of [Quickstart: Build and deploy apps to Azure Spring Apps](quickstart-deploy-apps.md).
192+
153193
## Clean up resources
154194

155195
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.
@@ -160,5 +200,5 @@ az group delete --name <resource-group>
160200

161201
## Next steps
162202

163-
* [Bind an Azure Database for MySQL instance to your application in Azure Spring Apps](how-to-bind-mysql.md)
203+
* [Bind an Azure Database for MySQL instance to your application in Azure Spring Apps](./how-to-bind-mysql.md)
164204
* [Use a managed identity to connect Azure SQL Database to an app in Azure Spring Apps](./connect-managed-identity-to-azure-sql.md)

0 commit comments

Comments
 (0)