Skip to content

Commit 45cef96

Browse files
authored
Merge pull request #77489 from ajlam/master
Add django SSL example
2 parents 9e197d6 + a9d1b44 commit 45cef96

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

articles/mysql/howto-configure-ssl.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: ajlam
55
ms.author: andrela
66
ms.service: mysql
77
ms.topic: conceptual
8-
ms.date: 01/24/2019
8+
ms.date: 05/21/2019
99
---
1010
# Configure SSL connectivity in your application to securely connect to Azure Database for MySQL
1111
Azure Database for MySQL supports connecting your Azure Database for MySQL server to client applications using Secure Sockets Layer (SSL). Enforcing SSL connections between your database server and your client applications helps protect against "man in the middle" attacks by encrypting the data stream between the server and your application.
@@ -15,6 +15,9 @@ Download the certificate needed to communicate over SSL with your Azure Database
1515
**For Microsoft Internet Explorer and Microsoft Edge:** After the download has completed, rename the certificate to BaltimoreCyberTrustRoot.crt.pem.
1616

1717
## Step 2: Bind SSL
18+
19+
For specific programming language connection strings, please refer to the [sample code](howto-configure-ssl.md#sample-code) below.
20+
1821
### Connecting to server using the MySQL Workbench over SSL
1922
Configure the MySQL Workbench to connect securely over SSL. From the Setup New Connection dialogue, navigate to the **SSL** tab. In the **SSL CA File:** field, enter the file location of the **BaltimoreCyberTrustRoot.crt.pem**.
2023
![save customized tile](./media/howto-configure-ssl/mysql-workbench-ssl.png)
@@ -78,24 +81,44 @@ try:
7881
except mysql.connector.Error as err:
7982
print(err)
8083
```
84+
8185
### Python (PyMySQL)
8286
```python
8387
conn = pymysql.connect(user = 'myadmin@mydemoserver',
8488
password = 'yourpassword',
8589
database = 'quickstartdb',
8690
host = 'mydemoserver.mysql.database.azure.com',
87-
ssl = {'ssl': {'ca': '/var/www/html/BaltimoreCyberTrustRoot.crt.pem'}})
91+
ssl = {'ssl': {'ssl-ca': '/var/www/html/BaltimoreCyberTrustRoot.crt.pem'}})
8892
```
93+
94+
### Django (PyMySQL)
95+
```python
96+
DATABASES = {
97+
'default': {
98+
'ENGINE': 'django.db.backends.mysql',
99+
'NAME': 'quickstartdb',
100+
'USER': 'myadmin@mydemoserver',
101+
'PASSWORD': 'yourpassword',
102+
'HOST': 'mydemoserver.mysql.database.azure.com',
103+
'PORT': '3306',
104+
'OPTIONS': {
105+
'ssl': {'ssl-ca': '/var/www/html/BaltimoreCyberTrustRoot.crt.pem'}
106+
}
107+
}
108+
}
109+
```
110+
89111
### Ruby
90112
```ruby
91113
client = Mysql2::Client.new(
92-
:host => 'mydemoserver.mysql.database.azure.com',
93-
:username => 'myadmin@mydemoserver',
94-
:password => 'yourpassword',
114+
:host => 'mydemoserver.mysql.database.azure.com',
115+
:username => 'myadmin@mydemoserver',
116+
:password => 'yourpassword',
95117
:database => 'quickstartdb',
96118
:ssl_ca => '/var/www/html/BaltimoreCyberTrustRoot.crt.pem'
97119
)
98120
```
121+
99122
### Golang
100123
```go
101124
rootCertPool := x509.NewCertPool()
@@ -108,7 +131,7 @@ var connectionString string
108131
connectionString = fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?allowNativePasswords=true&tls=custom",'myadmin@mydemoserver' , 'yourpassword', 'mydemoserver.mysql.database.azure.com', 'quickstartdb')
109132
db, _ := sql.Open("mysql", connectionString)
110133
```
111-
### JAVA(JDBC)
134+
### Java (MySQL Connector for Java)
112135
```java
113136
# generate truststore and keystore in code
114137
String importCert = " -import "+
@@ -135,7 +158,7 @@ properties.setProperty("user", 'myadmin@mydemoserver');
135158
properties.setProperty("password", 'yourpassword');
136159
conn = DriverManager.getConnection(url, properties);
137160
```
138-
### JAVA(MariaDB)
161+
### Java (MariaDB Connector for Java)
139162
```java
140163
# generate truststore and keystore in code
141164
String importCert = " -import "+

articles/mysql/howto-connect-webapp.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ author: ajlam
55
ms.author: andrela
66
ms.service: mysql
77
ms.topic: conceptual
8-
ms.date: 09/26/2018
8+
ms.date: 5/21/2019
99
---
1010

1111
# Connect an existing Azure App Service to Azure Database for MySQL server
1212
This topic explains how to connect an existing Azure App Service to your Azure Database for MySQL server.
1313

1414
## Before you begin
15-
Log in to the [Azure portal](https://portal.azure.com). Create an Azure Database for MySQL server. For details, refer to [How to create Azure Database for MySQL server from Portal](quickstart-create-mysql-server-database-using-azure-portal.md) or [How to create Azure Database for MySQL server using CLI](quickstart-create-mysql-server-database-using-azure-cli.md).
15+
Sign in to the [Azure portal](https://portal.azure.com). Create an Azure Database for MySQL server. For details, refer to [How to create Azure Database for MySQL server from Portal](quickstart-create-mysql-server-database-using-azure-portal.md) or [How to create Azure Database for MySQL server using CLI](quickstart-create-mysql-server-database-using-azure-cli.md).
1616

1717
Currently there are two solutions to enable access from an Azure App Service to an Azure Database for MySQL. Both solutions involve setting up server-level firewall rules.
1818

@@ -44,5 +44,22 @@ Though the Azure App service attempts to keep IP addresses constant over time, t
4444
## SSL configuration
4545
Azure Database for MySQL has SSL enabled by default. If your application is not using SSL to connect to the database, then you need to disable SSL on the MySQL server. For details on how to configure SSL, see [Using SSL with Azure Database for MySQL](howto-configure-ssl.md).
4646

47+
### Django (PyMySQL)
48+
```python
49+
DATABASES = {
50+
'default': {
51+
'ENGINE': 'django.db.backends.mysql',
52+
'NAME': 'quickstartdb',
53+
'USER': 'myadmin@mydemoserver',
54+
'PASSWORD': 'yourpassword',
55+
'HOST': 'mydemoserver.mysql.database.azure.com',
56+
'PORT': '3306',
57+
'OPTIONS': {
58+
'ssl': {'ssl-ca': '/var/www/html/BaltimoreCyberTrustRoot.crt.pem'}
59+
}
60+
}
61+
}
62+
```
63+
4764
## Next steps
4865
For more information about connection strings, refer to [Connection Strings](howto-connection-string.md).

0 commit comments

Comments
 (0)