Skip to content

Commit 1dd3b51

Browse files
Merge pull request #220693 from backwind1233/update_mysql
Provide a workaround in case users use MysqlConnectionPoolDataSource as the datasource to create jdbc connections with Azure AD
2 parents 40a8ae8 + 8ff543a commit 1dd3b51

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

articles/mysql/flexible-server/connect-java.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Quickstart: Use Java and JDBC with Azure Database for MySQLFlexible Server'
2+
title: 'Quickstart: Use Java and JDBC with Azure Database for MySQL Flexible Server'
33
description: Learn how to use Java and JDBC with an Azure Database for MySQL Flexible Server database.
44
author: mksuni
55
ms.author: sumuth
@@ -353,25 +353,37 @@ This file is an [Apache Maven](https://maven.apache.org/) file that configures y
353353

354354
### Prepare a configuration file to connect to Azure Database for MySQL
355355

356-
Run the following script in the project root directory to create a *src/main/resources/application.properties* file and add configuration details:
356+
Run the following script in the project root directory to create a *src/main/resources/database.properties* file and add configuration details:
357357

358358
#### [Passwordless connection (Recommended)](#tab/passwordless)
359359

360360
```bash
361-
mkdir -p src/main/resources && touch src/main/resources/application.properties
361+
mkdir -p src/main/resources && touch src/main/resources/database.properties
362362

363-
cat << EOF > src/main/resources/application.properties
363+
cat << EOF > src/main/resources/database.properties
364364
url=jdbc:mysql://${AZ_DATABASE_NAME}.mysql.database.azure.com:3306/demo?sslMode=REQUIRED&serverTimezone=UTC&defaultAuthenticationPlugin=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin&authenticationPlugins=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin
365365
user=${AZ_MYSQL_AD_NON_ADMIN_USERNAME}
366366
EOF
367367
```
368368

369+
> [!NOTE]
370+
> If you are using MysqlConnectionPoolDataSource class as the datasource in your application, please remove "defaultAuthenticationPlugin=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin" in the url.
371+
372+
```bash
373+
mkdir -p src/main/resources && touch src/main/resources/database.properties
374+
375+
cat << EOF > src/main/resources/database.properties
376+
url=jdbc:mysql://${AZ_DATABASE_NAME}.mysql.database.azure.com:3306/demo?sslMode=REQUIRED&serverTimezone=UTC&authenticationPlugins=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin
377+
user=${AZ_MYSQL_AD_NON_ADMIN_USERNAME}
378+
EOF
379+
```
380+
369381
#### [Password](#tab/password)
370382

371383
```bash
372-
mkdir -p src/main/resources && touch src/main/resources/application.properties
384+
mkdir -p src/main/resources && touch src/main/resources/database.properties
373385

374-
cat << EOF > src/main/resources/application.properties
386+
cat << EOF > src/main/resources/database.properties
375387
url=jdbc:mysql://${AZ_DATABASE_NAME}.mysql.database.azure.com:3306/demo?useSSL=true&sslMode=REQUIRED&serverTimezone=UTC
376388
user=${AZ_MYSQL_NON_ADMIN_USERNAME}
377389
password=${AZ_MYSQL_NON_ADMIN_PASSWORD}
@@ -421,7 +433,7 @@ public class DemoApplication {
421433
public static void main(String[] args) throws Exception {
422434
log.info("Loading application properties");
423435
Properties properties = new Properties();
424-
properties.load(DemoApplication.class.getClassLoader().getResourceAsStream("application.properties"));
436+
properties.load(DemoApplication.class.getClassLoader().getResourceAsStream("database.properties"));
425437

426438
log.info("Connecting to the database");
427439
Connection connection = DriverManager.getConnection(properties.getProperty("url"), properties);
@@ -452,12 +464,12 @@ public class DemoApplication {
452464

453465
[Having any issues? Let us know.](https://github.com/MicrosoftDocs/azure-docs/issues)
454466

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.
467+
This Java code will use the *database.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.
456468

457469
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.
458470

459471
> [!NOTE]
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.
472+
> The database credentials are stored in the *user* and *password* properties of the *database.properties* file. Those credentials are used when executing `DriverManager.getConnection(properties.getProperty("url"), properties);`, as the properties file is passed as an argument.
461473
462474
> [!NOTE]
463475
> The `AbandonedConnectionCleanupThread.uncheckedShutdown();` line at the end is a MySQL driver specific command to destroy an internal thread when shutting down the application.
@@ -730,4 +742,4 @@ az group delete \
730742
## Next steps
731743

732744
> [!div class="nextstepaction"]
733-
> [Migrate your MySQL database to Azure Database for MySQL using dump and restore](../concepts-migrate-dump-restore.md)
745+
> [Migrate your MySQL database to Azure Database for MySQL using dump and restore](../concepts-migrate-dump-restore.md)

articles/mysql/single-server/connect-java.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Replace the placeholders with the following values, which are used throughout th
5656

5757
- `<YOUR_DATABASE_SERVER_NAME>`: The name of your MySQL server, which should be unique across Azure.
5858
- `<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_LOCAL_IP_ADDRESS>`: The IP address of your local computer, from which you'll run your Spring Boot application. One convenient way to find it is to open [whatismyip.akamai.com](http://whatismyip.akamai.com/).
59+
- `<YOUR_LOCAL_IP_ADDRESS>`: The IP address of your local computer, from which you'll run your application. One convenient way to find it is to open [whatismyip.akamai.com](http://whatismyip.akamai.com/).
6060

6161
### [Password](#tab/password)
6262

@@ -345,25 +345,37 @@ This file is an [Apache Maven](https://maven.apache.org/) file that configures y
345345

346346
### Prepare a configuration file to connect to Azure Database for MySQL
347347

348-
Run the following script in the project root directory to create a *src/main/resources/application.properties* file and add configuration details:
348+
Run the following script in the project root directory to create a *src/main/resources/database.properties* file and add configuration details:
349349

350350
#### [Passwordless connection (Recommended)](#tab/passwordless)
351351

352352
```bash
353-
mkdir -p src/main/resources && touch src/main/resources/application.properties
353+
mkdir -p src/main/resources && touch src/main/resources/database.properties
354354

355-
cat << EOF > src/main/resources/application.properties
355+
cat << EOF > src/main/resources/database.properties
356356
url=jdbc:mysql://${AZ_DATABASE_SERVER_NAME}.mysql.database.azure.com:3306/${AZ_DATABASE_NAME}?sslMode=REQUIRED&serverTimezone=UTC&defaultAuthenticationPlugin=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin&authenticationPlugins=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin
357357
user=${AZ_MYSQL_AD_NON_ADMIN_USERNAME}@${AZ_DATABASE_SERVER_NAME}
358358
EOF
359359
```
360360

361+
362+
> [!NOTE]
363+
> If you are using MysqlConnectionPoolDataSource class as the datasource in your application, please remove "defaultAuthenticationPlugin=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin" in the url.
364+
365+
```bash
366+
mkdir -p src/main/resources && touch src/main/resources/database.properties
367+
368+
cat << EOF > src/main/resources/database.properties
369+
url=jdbc:mysql://${AZ_DATABASE_SERVER_NAME}.mysql.database.azure.com:3306/${AZ_DATABASE_NAME}?sslMode=REQUIRED&serverTimezone=UTC&authenticationPlugins=com.azure.identity.providers.mysql.AzureIdentityMysqlAuthenticationPlugin
370+
user=${AZ_MYSQL_AD_NON_ADMIN_USERNAME}@${AZ_DATABASE_SERVER_NAME}
371+
EOF
372+
```
361373
#### [Password](#tab/password)
362374

363375
```bash
364-
mkdir -p src/main/resources && touch src/main/resources/application.properties
376+
mkdir -p src/main/resources && touch src/main/resources/database.properties
365377

366-
cat << EOF > src/main/resources/application.properties
378+
cat << EOF > src/main/resources/database.properties
367379
url=jdbc:mysql://${AZ_DATABASE_SERVER_NAME}.mysql.database.azure.com:3306/${AZ_DATABASE_NAME}?useSSL=true&sslMode=REQUIRED&serverTimezone=UTC
368380
user=${AZ_MYSQL_NON_ADMIN_USERNAME}@${AZ_DATABASE_SERVER_NAME}
369381
password=${AZ_MYSQL_NON_ADMIN_PASSWORD}
@@ -417,7 +429,7 @@ public class DemoApplication {
417429
public static void main(String[] args) throws Exception {
418430
log.info("Loading application properties");
419431
Properties properties = new Properties();
420-
properties.load(DemoApplication.class.getClassLoader().getResourceAsStream("application.properties"));
432+
properties.load(DemoApplication.class.getClassLoader().getResourceAsStream("database.properties"));
421433

422434
log.info("Connecting to the database");
423435
Connection connection = DriverManager.getConnection(properties.getProperty("url"), properties);
@@ -446,12 +458,12 @@ public class DemoApplication {
446458
}
447459
```
448460

449-
This Java code will use the *application.properties* and the *schema.sql* files that you created earlier. After connecting to the MySQL server, you can create a schema to store your data.
461+
This Java code will use the *database.properties* and the *schema.sql* files that you created earlier. After connecting to the MySQL server, you can create a schema to store your data.
450462

451463
In this file, you can see that we commented methods to insert, read, update and delete data. You'll implement those methods in the rest of this article, and you'll be able to uncomment them one after each other.
452464

453465
> [!NOTE]
454-
> 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.
466+
> The database credentials are stored in the *user* and *password* properties of the *database.properties* file. Those credentials are used when executing `DriverManager.getConnection(properties.getProperty("url"), properties);`, as the properties file is passed as an argument.
455467
456468
> [!NOTE]
457469
> The `AbandonedConnectionCleanupThread.uncheckedShutdown();` line at the end is a MySQL driver command to destroy an internal thread when shutting down the application. You can safely ignore this line.

0 commit comments

Comments
 (0)