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
This topic explains how to connect an application your Azure Database for MySQL server with redirection mode. Redirection aims to reduce network latency between client applications and MySQL servers by allowing applications to connect directly to backend server nodes.
19
+
This article explains how to connect an application to your Azure Database for MySQL server with redirection mode. Redirection reduces network latency between client applications and MySQL servers by allowing applications to connect directly to backend server nodes.
19
20
20
21
## Before you begin
21
-
Sign in to the [Azure portal](https://portal.azure.com). Create an Azure Database for MySQL server with engine version 5.6, 5.7, or 8.0.
22
+
23
+
Sign in to the [Azure portal](https://portal.azure.com). Create an Azure Database for MySQL server with engine version 5.6, 5.7, or 8.0.
22
24
23
25
For details, refer to how to create an Azure Database for MySQL server using the [Azure portal](quickstart-create-mysql-server-database-using-azure-portal.md) or [Azure CLI](quickstart-create-mysql-server-database-using-azure-cli.md).
24
26
25
-
> [!IMPORTANT]
27
+
> [!IMPORTANT]
26
28
> Redirection is currently not supported with [Private Link for Azure Database for MySQL](concepts-data-access-security-private-link.md).
27
29
28
30
## Enable redirection
@@ -31,65 +33,66 @@ On your Azure Database for MySQL server, configure the `redirect_enabled` parame
31
33
32
34
## PHP
33
35
34
-
Support for redirection in PHP applications is available through the [mysqlnd_azure](https://github.com/microsoft/mysqlnd_azure) extension, developed by Microsoft.
36
+
Support for redirection in PHP applications is available through the [mysqlnd_azure](https://github.com/microsoft/mysqlnd_azure) extension, developed by Microsoft.
35
37
36
-
The mysqlnd_azure extension is available to add to PHP applications through PECL and it is highly recommended to install and configure the extension through the officially published [PECL package](https://pecl.php.net/package/mysqlnd_azure).
38
+
The mysqlnd_azure extension is available to add to PHP applications through PECL, and it's highly recommended to install and configure the extension through the officially published [PECL package](https://pecl.php.net/package/mysqlnd_azure).
37
39
38
-
> [!IMPORTANT]
40
+
> [!IMPORTANT]
39
41
> Support for redirection in the PHP [mysqlnd_azure](https://github.com/microsoft/mysqlnd_azure) extension is currently in preview.
40
42
41
43
### Redirection logic
42
44
43
-
>[!IMPORTANT]
45
+
>[!IMPORTANT]
44
46
> Redirection logic/behavior beginning version 1.1.0 was updated and **it is recommended to use version 1.1.0+**.
45
47
46
48
The redirection behavior is determined by the value of `mysqlnd_azure.enableRedirect`. The table below outlines the behavior of redirection based on the value of this parameter beginning in **version 1.1.0+**.
47
49
48
-
If you are using an older version of the mysqlnd_azure extension (version 1.0.0-1.0.3), the redirection behavior is determined by the value of `mysqlnd_azure.enabled`. The valid values are `off` (acts similarly as the behavior outlined in the table below) and `on` (acts like `preferred` in the table below).
50
+
If you're using an older version of the mysqlnd_azure extension (version 1.0.0-1.0.3), the redirection behavior is determined by the value of `mysqlnd_azure.enabled`. The valid values are `off` (acts similarly as the behavior outlined in the table below) and `on` (acts like `preferred` in the table below).
|`on` or `1`|- If the connection does not use SSL on the driver side, no connection will be made. The following error will be returned: *"mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."*<br>- If SSL is used on the driver side, but redirection is not supported on the server, the first connection is aborted and the following error is returned: *"Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet redirection protocol."*<br>- If the MySQL server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.|
54
-
|`preferred` or `2`<br> (default value)|- mysqlnd_azure will use redirection if possible.<br>- If the connection does not use SSL on the driver side, the server does not support redirection, or the redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fall back to the first proxy connection.|
|`on` or `1`|- If the connection doesn't use SSL on the driver side, no connection is made. The following error is returned: *"mysqlnd_azure.enableRedirect is on, but SSL option isn't set in the connection string. Redirection is only possible with SSL."*<br />- If SSL is used on the driver side, but the redirection isn't supported on the server, the first connection is aborted, and the following error is returned: *"Connection aborted because redirection isn't enabled on the MySQL server or the network package doesn't meet redirection protocol."*<br />- If the MySQL server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.|
56
+
|`preferred` or `2`<br />(default value)|- mysqlnd_azure will use redirection if possible.<br />- If the connection doesn't use SSL on the driver side, the server doesn't support redirection, or the redirected connection fails to connect for any nonfatal reason while the proxy connection is still a valid one, it falls back to the first proxy connection.|
55
57
56
-
For successful connection to Azure database for MySQL single server using `mysqlnd_azure.enableRedirect` you need to follow mandatory steps of combining your root certificate as per the compliance requirements. For more details please visit [link](./concepts-certificate-rotation.md#do-i-need-to-make-any-changes-on-my-client-to-maintain-connectivity).
58
+
For a successful connection to Azure Database for MySQL single server using `mysqlnd_azure.enableRedirect`, you need to follow mandatory steps of combining your root certificate as per the compliance requirements. For more details, please visit [link](./concepts-certificate-rotation.md#do-i-need-to-make-any-changes-on-my-client-to-maintain-connectivity).
57
59
58
-
The subsequent sections of the document will outline how to install the `mysqlnd_azure` extension using PECL and set the value of this parameter.
60
+
The subsequent sections of the document outline how to install the `mysqlnd_azure` extension using PECL and set the value of this parameter.
59
61
60
62
### Ubuntu Linux
61
63
62
-
#### Prerequisites
64
+
#### Prerequisites
65
+
63
66
- PHP versions 7.2.15+ and 7.3.2+
64
-
- PHP PEAR
67
+
- PHP PEAR
65
68
- php-mysql
66
69
- Azure Database for MySQL server
67
70
68
-
1. Install [mysqlnd_azure](https://github.com/microsoft/mysqlnd_azure) with [PECL](https://pecl.php.net/package/mysqlnd_azure). It is recommended to use version 1.1.0+.
71
+
1. Install [mysqlnd_azure](https://github.com/microsoft/mysqlnd_azure) with [PECL](https://pecl.php.net/package/mysqlnd_azure). It's recommended to use version 1.1.0+.
69
72
70
73
```bash
71
74
sudo pecl install mysqlnd_azure
72
75
```
73
76
74
-
2. Locate the extension directory (`extension_dir`) by running the below:
77
+
1. Locate the extension directory (`extension_dir`) by running the below:
75
78
76
79
```bash
77
80
php -i | grep "extension_dir"
78
81
```
79
82
80
-
3. Change directories to the returned folder and ensure `mysqlnd_azure.so` is located in this folder.
83
+
1. Change directories to the returned folder and ensure `mysqlnd_azure.so` is located in this folder.
81
84
82
-
4. Locate the folder for .ini files by running the below:
85
+
1. Locate the folder for .ini files by running the below:
83
86
84
87
```bash
85
88
php -i | grep "dir for additional .ini files"
86
89
```
87
90
88
-
5. Change directories to this returned folder.
91
+
1. Change directories to this returned folder.
89
92
90
-
6. Create a new .ini file for`mysqlnd_azure`. Make sure the alphabet order of the name is after that of mysqnld, since the modules are loaded according to the name order of the ini files. For example, if`mysqlnd` .ini is named `10-mysqlnd.ini`, name the mysqlnd ini as `20-mysqlnd-azure.ini`.
93
+
1. Create a new .ini file for`mysqlnd_azure`. Make sure the alphabet order of the name is after that of mysqnld, since the modules are loaded according to the name order of the ini files. For example, if`mysqlnd` .ini is named `10-mysqlnd.ini`, name the mysqlnd ini as `20-mysqlnd-azure.ini`.
91
94
92
-
7. Within the new .ini file, add the following lines to enable redirection.
95
+
1. Within the new .ini file, add the following lines to enable redirection.
93
96
94
97
```bash
95
98
extension=mysqlnd_azure
@@ -98,52 +101,55 @@ The subsequent sections of the document will outline how to install the `mysqlnd
98
101
99
102
### Windows
100
103
101
-
#### Prerequisites
104
+
#### Prerequisites
105
+
102
106
- PHP versions 7.2.15+ and 7.3.2+
103
107
- php-mysql
104
108
- Azure Database for MySQL server
105
109
106
-
1. Determine if you are running a x64 or x86 version of PHP by running the following command:
110
+
1. Determine if you're running a x64 or x86 version of PHP by running the following command:
107
111
108
112
```cmd
109
113
php -i | findstr "Thread"
110
114
```
111
115
112
-
2. Download the corresponding x64 or x86 version of the [mysqlnd_azure](https://github.com/microsoft/mysqlnd_azure) DLL from [PECL](https://pecl.php.net/package/mysqlnd_azure) that matches your version of PHP. It is recommended to use version 1.1.0+.
116
+
1. Download the corresponding x64 or x86 version of the [mysqlnd_azure](https://github.com/microsoft/mysqlnd_azure) DLL from [PECL](https://pecl.php.net/package/mysqlnd_azure) that matches your version of PHP. It's recommended to use version 1.1.0+.
113
117
114
-
3. Extract the zip file and find the DLL named `php_mysqlnd_azure.dll`.
118
+
1. Extract the zip file and find the DLL named `php_mysqlnd_azure.dll`.
115
119
116
-
4. Locate the extension directory (`extension_dir`) by running the below command:
120
+
1. Locate the extension directory (`extension_dir`) by running the below command:
117
121
118
122
```cmd
119
123
php -i | find "extension_dir"
120
124
```
121
125
122
-
5. Copy the `php_mysqlnd_azure.dll` file into the directory returned in step 4.
126
+
1. Copy the `php_mysqlnd_azure.dll` file into the directory returned in step 4.
123
127
124
-
6. Locate the PHP folder containing the `php.ini` file using the following command:
128
+
1. Locate the PHP folder containing the `php.ini` file using the following command:
125
129
126
130
```cmd
127
131
php -i | find "Loaded Configuration File"
128
132
```
129
133
130
-
7. Modify the `php.ini` file and add the following extra lines to enable redirection.
134
+
1. Modify the `php.ini` file and add the following extra lines to enable redirection.
135
+
136
+
Under the Dynamic Extensions section:
131
137
132
-
Under the Dynamic Extensions section:
133
138
```cmd
134
139
extension=mysqlnd_azure
135
140
```
136
-
137
-
Under the Module Settings section:
138
-
```cmd
141
+
142
+
Under the Module Settings section:
143
+
144
+
```cmd
139
145
[mysqlnd_azure]
140
146
mysqlnd_azure.enableRedirect = on/off/preferred
141
147
```
142
148
143
149
### Confirm redirection
144
150
145
-
You can also confirm redirection is configured with the below sample PHP code. Create a PHP file called `mysqlConnect.php` and paste the below code. Update the server name, username, and password with your own.
146
-
151
+
You can also confirm redirection is configured with the below sample PHP code. Create a PHP file called `mysqlConnect.php` and paste the below code. Update the server name, username, and password with your own.
0 commit comments