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
-[Azure Cloud Shell](../../cloud-shell/quickstart.md) or [Azure CLI](/cli/azure/install-azure-cli). We recommend Azure Cloud Shell so you'll be logged in automatically and have access to all the tools you'll need.
34
33
- A supported [Java Development Kit](/azure/developer/java/fundamentals/java-support-on-azure), version 8 (included in Azure Cloud Shell).
35
34
- The [Apache Maven](https://maven.apache.org/) build tool.
36
35
37
36
## Prepare the working environment
38
37
39
-
We are going to use environment variables to limit typing mistakes, and to make it easier for you to customize the following configuration for your specific needs.
40
-
41
-
Set up those environment variables by using the following commands:
38
+
First, use the following command to set up some environment variables.
export CURRENT_USERNAME=$(az ad signed-in-user show --query userPrincipalName -o tsv)
52
49
export CURRENT_USER_OBJECTID=$(az ad signed-in-user show --query id -o tsv)
53
50
```
54
51
55
52
Replace the placeholders with the following values, which are used throughout this article:
56
53
57
-
-`<YOUR_DATABASE_NAME>`: The name of your MySQL server. It should be unique across Azure.
54
+
-`<YOUR_DATABASE_NAME>`: The name of your MySQL server, which should be unique across Azure.
58
55
-`<YOUR_AZURE_REGION>`: The Azure region you'll use. You can use `eastus` by default, but we recommend that you configure a region closer to where you live. You can see the full list of available regions by entering `az account list-locations`.
59
-
-`<YOUR_USER_ASSIGNED_MANAGEMED_IDENTITY_NAME>`: The name of your user assigned managed identity server. It should be unique across Azure.
56
+
-`<YOUR_USER_ASSIGNED_MANAGED_IDENTITY_NAME>`: The name of your user assigned managed identity server, which should be unique across Azure.
Replace the placeholders with the following values, which are used throughout this article:
74
71
75
-
-`<YOUR_DATABASE_NAME>`: The name of your MySQL server. It should be unique across Azure.
76
-
-`<YOUR_AZURE_REGION>`: The Azure region you'll use. You can use `eastus` by default, but we recommend that you configure a region closer to where you live. You can have the full list of available regions by entering `az account list-locations`.
72
+
-`<YOUR_DATABASE_NAME>`: The name of your MySQL server, which should be unique across Azure.
73
+
-`<YOUR_AZURE_REGION>`: The Azure region you'll use. You can use `eastus` by default, but we recommend that you configure a region closer to where you live. You can see the full list of available regions by entering `az account list-locations`.
77
74
-`<YOUR_MYSQL_ADMIN_PASSWORD>` and `<YOUR_MYSQL_NON_ADMIN_PASSWORD>`: The password of your MySQL database server. That password should have a minimum of eight characters. The characters should be from three of the following categories: English uppercase letters, English lowercase letters, numbers (0-9), and non-alphanumeric characters (!, $, #, %, and so on).
78
75
79
76
---
@@ -91,7 +88,7 @@ az group create \
91
88
92
89
### Create a MySQL server and set up admin user
93
90
94
-
The first thing we'll create is a managed MySQL server.
91
+
The first thing you'll create is a managed MySQL server.
95
92
96
93
> [!NOTE]
97
94
> You can read more detailed information about creating MySQL servers in [Create an Azure Database for MySQL server by using the Azure portal](./quickstart-create-server-portal.md).
@@ -115,25 +112,24 @@ az mysql flexible-server create \
115
112
--output tsv
116
113
```
117
114
118
-
Run the following command to create **User-Assigned Identity** for assigning:
115
+
Run the following command to create a user-assigned identity for assigning:
119
116
120
117
```azurecli
121
118
az identity create \
122
-
--resource-group $AZ_RESOURCE_GROUP \
123
-
--name $AZ_USER_IDENTITY_NAME
119
+
--resource-group $AZ_RESOURCE_GROUP \
120
+
--name $AZ_USER_IDENTITY_NAME
124
121
```
125
122
126
123
> [!IMPORTANT]
127
-
> After creating **User-Assigned Identity**, ask your **Global Administrator** or **Privileged Role Administrator** to grant three permissions: `User.Read.All`, `GroupMember.Read.All` and `Application.Read.ALL` for this identity.
128
-
> More information refer [Active Directory authentication](/azure/mysql/flexible-server/concepts-azure-ad-authentication#permissions).
124
+
> After creating the user-assigned identity, ask your *Global Administrator* or *Privileged Role Administrator* to grant the following permissions for this identity: `User.Read.All`, `GroupMember.Read.All`, and `Application.Read.ALL`. For more information, see the [Permissions](/azure/mysql/flexible-server/concepts-azure-ad-authentication#permissions) section of [Active Directory authentication](/azure/mysql/flexible-server/concepts-azure-ad-authentication).
129
125
130
126
Run the following command to assign the identity to MySQL server for creating Azure AD admin:
131
127
132
128
```azurecli
133
129
az mysql flexible-server identity assign \
134
-
--resource-group $AZ_RESOURCE_GROUP \
135
-
--server-name $AZ_DATABASE_NAME \
136
-
--identity $AZ_USER_IDENTITY_NAME
130
+
--resource-group $AZ_RESOURCE_GROUP \
131
+
--server-name $AZ_DATABASE_NAME \
132
+
--identity $AZ_USER_IDENTITY_NAME
137
133
```
138
134
139
135
Run the following command to set the Azure AD admin user:
@@ -169,19 +165,17 @@ This command creates a small MySQL server.
169
165
170
166
---
171
167
172
-
The MySQL server that you created has a empty database called **flexibleserverdb**. We will use this database for this article.
168
+
The MySQL server that you created has a empty database called `flexibleserverdb`.
173
169
174
170
[Having any issues? Let us know.](https://github.com/MicrosoftDocs/azure-docs/issues)
175
171
176
172
### Configure a firewall rule for your MySQL server
177
173
178
174
Azure Database for MySQL instances are secured by default. They have a firewall that doesn't allow any incoming connection.
179
175
180
-
You can skip this step if you are using bash, because the `flexible-server create` command already detected your local IP address and set it on MySQL server.
176
+
You can skip this step if you're using Bash because the `flexible-server create` command already detected your local IP address and set it on MySQL server.
181
177
182
-
But if you're connecting to your MySQL server from WSL on a Windows computer, you'll need to add the WSL host ID to your firewall.
183
-
184
-
Obtain the IP address of your host machine by running the following command in WSL:
178
+
If you're connecting to your MySQL server from Windows Subsystem for Linux (WSL) on a Windows computer, you'll need to add the WSL host ID to your firewall. Obtain the IP address of your host machine by running the following command in WSL:
185
179
186
180
```bash
187
181
cat /etc/resolv.conf
@@ -287,7 +281,7 @@ rm create_user.sql
287
281
288
282
### Create a new Java project
289
283
290
-
Using your favorite IDE, create a new Java project, and add a `pom.xml` file in its root directory:
284
+
Using your favorite IDE, create a new Java project, and add a *pom.xml* file in its root directory:
@@ -352,7 +346,7 @@ Using your favorite IDE, create a new Java project, and add a `pom.xml` file in
352
346
353
347
---
354
348
355
-
This file is an [Apache Maven](https://maven.apache.org/) that configures our project to use:
349
+
This file is an [Apache Maven](https://maven.apache.org/)file that configures your project to use:
356
350
357
351
- Java 8
358
352
- A recent MySQL driver for Java
@@ -387,11 +381,11 @@ EOF
387
381
---
388
382
389
383
> [!NOTE]
390
-
> We append `?serverTimezone=UTC`to the configuration property `url`, to tell the JDBC driver to use the UTC date format (or Coordinated Universal Time) when connecting to the database. Otherwise, our Java server would not use the same date format as the database, which would result in an error.
384
+
> The configuration property `url` has `?serverTimezone=UTC`appended to tell the JDBC driver to use the UTC date format (or Coordinated Universal Time) when connecting to the database. Otherwise, your Java server would not use the same date format as the database, which would result in an error.
391
385
392
386
### Create an SQL file to generate the database schema
393
387
394
-
We will use a *src/main/resources/`schema.sql`* file in order to create a database schema. Create that file, with the following content:
388
+
You'll use a *src/main/resources/schema.sql* file in order to create a database schema. Create that file, with the following content:
395
389
396
390
```sql
397
391
DROPTABLE IF EXISTS todo;
@@ -440,14 +434,14 @@ public class DemoApplication {
440
434
statement.execute(scanner.nextLine());
441
435
}
442
436
443
-
/*
444
-
Todo todo = new Todo(1L, "configuration", "congratulations, you have set up JDBC correctly!", true);
437
+
/*
438
+
Todo todo = new Todo(1L, "configuration", "congratulations, you have set up JDBC correctly!", true);
445
439
insertData(todo, connection);
446
440
todo = readData(connection);
447
441
todo.setDetails("congratulations, you have updated data!");
448
442
updateData(todo, connection);
449
443
deleteData(todo, connection);
450
-
*/
444
+
*/
451
445
452
446
log.info("Closing database connection");
453
447
connection.close();
@@ -458,9 +452,9 @@ public class DemoApplication {
458
452
459
453
[Having any issues? Let us know.](https://github.com/MicrosoftDocs/azure-docs/issues)
460
454
461
-
This Java code will use the *application.properties* and the *schema.sql* files that we created earlier, in order to connect to the MySQL server and create a schema that will store our data.
455
+
This Java code will use the *application.properties* and the *schema.sql* files that you created earlier, in order to connect to the MySQL server and create a schema that will store your data.
462
456
463
-
In this file, you can see that we commented methods to insert, read, update and delete data: we will code those methods in the rest of this article, and you will be able to uncomment them one after each other.
457
+
In this file, you can see that we commented methods to insert, read, update and delete data: you'll code those methods in the rest of this article, and you'll be able to uncomment them one after each other.
464
458
465
459
> [!NOTE]
466
460
> The database credentials are stored in the *user* and *password* properties of the *application.properties* file. Those credentials are used when executing `DriverManager.getConnection(properties.getProperty("url"), properties);`, as the properties file is passed as an argument.
@@ -476,7 +470,7 @@ You can now execute this main class with your favorite tool:
476
470
477
471
The application should connect to the Azure Database for MySQL, create a database schema, and then close the connection, as you should see in the console logs:
478
472
479
-
```
473
+
```output
480
474
[INFO ] Loading application properties
481
475
[INFO ] Connecting to the database
482
476
[INFO ] Database connection test: demo
@@ -581,7 +575,7 @@ insertData(todo, connection);
581
575
582
576
Executing the main class should now produce the following output:
583
577
584
-
```
578
+
```output
585
579
[INFO ] Loading application properties
586
580
[INFO ] Connecting to the database
587
581
[INFO ] Database connection test: demo
@@ -592,7 +586,7 @@ Executing the main class should now produce the following output:
592
586
593
587
### Reading data from Azure Database for MySQL
594
588
595
-
Let's read the data previously inserted, to validate that our code works correctly.
589
+
Next, read the data previously inserted to validate that your code works correctly.
596
590
597
591
In the *src/main/java/DemoApplication.java* file, after the `insertData` method, add the following method to read data from the database:
598
592
@@ -623,7 +617,7 @@ todo = readData(connection);
623
617
624
618
Executing the main class should now produce the following output:
625
619
626
-
```
620
+
```output
627
621
[INFO ] Loading application properties
628
622
[INFO ] Connecting to the database
629
623
[INFO ] Database connection test: demo
@@ -638,7 +632,7 @@ Executing the main class should now produce the following output:
638
632
639
633
### Updating data in Azure Database for MySQL
640
634
641
-
Let's update the data we previously inserted.
635
+
Next, update the data you previously inserted.
642
636
643
637
Still in the *src/main/java/DemoApplication.java* file, after the `readData` method, add the following method to update data inside the database:
644
638
@@ -666,7 +660,7 @@ updateData(todo, connection);
666
660
667
661
Executing the main class should now produce the following output:
668
662
669
-
```
663
+
```output
670
664
[INFO ] Loading application properties
671
665
[INFO ] Connecting to the database
672
666
[INFO ] Database connection test: demo
@@ -682,7 +676,7 @@ Executing the main class should now produce the following output:
682
676
683
677
### Deleting data in Azure Database for MySQL
684
678
685
-
Finally, let's delete the data we previously inserted.
679
+
Finally, delete the data you previously inserted.
686
680
687
681
Still in the *src/main/java/DemoApplication.java* file, after the `updateData` method, add the following method to delete data inside the database:
688
682
@@ -704,7 +698,7 @@ deleteData(todo, connection);
704
698
705
699
Executing the main class should now produce the following output:
0 commit comments