You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "Quickstart - Integrate with Azure Database for MySQL"
3
3
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.
# 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
20
20
21
21
## Prerequisites
22
22
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
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).
38
24
39
25
## Prepare an Azure Database for MySQL instance
40
26
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.
42
28
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>
45
36
```
46
37
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.
48
40
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.).
58
43
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.
60
45
61
-
```azcli
62
-
az mysql server firewall-rule create --name allAzureIPs \
> The service binding feature in Azure Spring Apps is being deprecated in favor of Service Connector.
77
52
78
-
1. Increase connection timeout.
53
+
### [Azure CLI](#tab/azure-cli)
79
54
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.
85
56
86
-
1. Create database in the MySQL server and set corresponding settings.
57
+
```azurecli-interactive
58
+
az provider register --namespace Microsoft.ServiceLinker
59
+
```
87
60
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.
92
62
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)
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`.
103
87
104
-
Type 'help;'or'\h' for help. Type '\c' to clear the current input statement.
88
+
### [Portal](#tab/azure-portal)
105
89
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**.
108
93
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.":::
111
95
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.
| **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. |
117
106
118
-
mysql>SELECT name FROMmysql.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.":::
120
108
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.
124
110
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.
126
112
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.
134
114
135
-
## Update Apps to use MySQL database
115
+
---
116
+
117
+
## Check connection to MySQL database
118
+
119
+
### [Azure CLI](#tab/azure-cli)
136
120
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.
The configured values (except username/password) is validated success
178
139
```
179
140
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
+
180
152
## Clean up resources
181
153
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 resourcegroup 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.
0 commit comments