Skip to content

Commit 3da7525

Browse files
committed
update mysql msi sample
1 parent 5d25931 commit 3da7525

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

articles/service-connector/includes/code-mysql-me-id.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,28 @@ await connection.OpenAsync();
6565
1. Get the connection string from the environment variable, and add the plugin name to connect to the database:
6666

6767
```java
68-
String url = System.getenv("AZURE_MYSQL_CONNECTIONSTRING");
68+
String url = System.getenv("AZURE_MYSQL_CONNECTIONSTRING");
6969
String pluginName = "com.azure.identity.extensions.jdbc.mysql.AzureMysqlAuthenticationPlugin";
70-
Connection connection = DriverManager.getConnection(url + "&defaultAuthenticationPlugin=" +
71-
pluginName + "&authenticationPlugins=" + pluginName);
70+
71+
Properties properties = new Properties();
72+
properties.put("defaultAuthenticationPlugin", pluginName);
73+
properties.put("authenticationPlugins", pluginName);
74+
75+
// Uncomment the following lines corresponding to the authentication type you want to use.
76+
77+
// for user-assigned managed identity
78+
// String clientId = System.getenv('AZURE_MYSQL_CLIENTID')
79+
// properties.put("azure.clientId","${YOUR_CLIENT_ID}");
80+
81+
// For service principal
82+
// String tenantId = System.getenv('AZURE_MYSQL_TENANTID')
83+
// String clientId = System.getenv('AZURE_MYSQL_CLIENTID')
84+
// String clientSecret = System.getenv('AZURE_MYSQL_CLIENTSECRET')
85+
// properties.put("azure.clientId","${YOUR_CLIENT_ID}");
86+
// properties.put("azure.clientSecret","${YOUR_CLIENT_SECRET}");
87+
// properties.put("azure.tenantId","${YOUR_TENANT_ID}");
88+
89+
Connection connection = DriverManager.getConnection(url, properties);
7290
```
7391

7492
For more information, see [Use Java and JDBC with Azure Database for MySQL - Flexible Server](/azure/mysql/flexible-server/connect-java?tabs=passwordless).

0 commit comments

Comments
 (0)