Skip to content

Commit 67e5efa

Browse files
committed
improve acrolinx
1 parent d386b75 commit 67e5efa

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed
Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
---
22
title: Connect with redirection - Azure Database for MySQL
3-
description: This article describes how you can configure you application to connect to Azure Database for MySQL with redirection.
4-
ms.service: mysql
5-
ms.subservice: single-server
3+
description: This article describes how you can configure your application to connect to Azure Database for MySQL with redirection.
64
author: savjani
75
ms.author: pariks
6+
ms.reviewer: maghan
7+
ms.date: 03/27/2023
8+
ms.service: mysql
9+
ms.subservice: single-server
810
ms.topic: how-to
9-
ms.date: 06/20/2022
1011
---
1112

1213
# Connect to Azure Database for MySQL with redirection
1314

1415
[!INCLUDE[applies-to-mysql-single-server](../includes/applies-to-mysql-single-server.md)]
1516

16-
[!INCLUDE[azure-database-for-mysql-single-server-deprecation](../includes/azure-database-for-mysql-single-server-deprecation.md)]
17+
[!INCLUDE[Azure-database-for-mysql-single-server-deprecation](../includes/Azure-database-for-mysql-single-server-deprecation.md)]
1718

18-
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.
1920

2021
## 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.
2224

2325
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).
2426

25-
> [!IMPORTANT]
27+
> [!IMPORTANT]
2628
> Redirection is currently not supported with [Private Link for Azure Database for MySQL](concepts-data-access-security-private-link.md).
2729
2830
## Enable redirection
@@ -31,65 +33,66 @@ On your Azure Database for MySQL server, configure the `redirect_enabled` parame
3133

3234
## PHP
3335

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.
3537

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).
3739

38-
> [!IMPORTANT]
40+
> [!IMPORTANT]
3941
> Support for redirection in the PHP [mysqlnd_azure](https://github.com/microsoft/mysqlnd_azure) extension is currently in preview.
4042
4143
### Redirection logic
4244

43-
>[!IMPORTANT]
45+
> [!IMPORTANT]
4446
> Redirection logic/behavior beginning version 1.1.0 was updated and **it is recommended to use version 1.1.0+**.
4547
4648
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+**.
4749

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).
4951

50-
|**mysqlnd_azure.enableRedirect value**| **Behavior**|
51-
|----------------------------------------|-------------|
52-
|`off` or `0`|Redirection will not be used. |
53-
|`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.|
52+
| **mysqlnd_azure.enableRedirect value** | **Behavior** |
53+
| --- | --- |
54+
| `off` or `0` | Redirection won't be used. |
55+
| `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. |
5557

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).
5759

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.
5961

6062
### Ubuntu Linux
6163

62-
#### Prerequisites
64+
#### Prerequisites
65+
6366
- PHP versions 7.2.15+ and 7.3.2+
64-
- PHP PEAR
67+
- PHP PEAR
6568
- php-mysql
6669
- Azure Database for MySQL server
6770

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+.
6972

7073
```bash
7174
sudo pecl install mysqlnd_azure
7275
```
7376

74-
2. Locate the extension directory (`extension_dir`) by running the below:
77+
1. Locate the extension directory (`extension_dir`) by running the below:
7578

7679
```bash
7780
php -i | grep "extension_dir"
7881
```
7982

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.
8184

82-
4. Locate the folder for .ini files by running the below:
85+
1. Locate the folder for .ini files by running the below:
8386

8487
```bash
8588
php -i | grep "dir for additional .ini files"
8689
```
8790

88-
5. Change directories to this returned folder.
91+
1. Change directories to this returned folder.
8992

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`.
9194

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.
9396

9497
```bash
9598
extension=mysqlnd_azure
@@ -98,52 +101,55 @@ The subsequent sections of the document will outline how to install the `mysqlnd
98101

99102
### Windows
100103

101-
#### Prerequisites
104+
#### Prerequisites
105+
102106
- PHP versions 7.2.15+ and 7.3.2+
103107
- php-mysql
104108
- Azure Database for MySQL server
105109

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:
107111
108112
```cmd
109113
php -i | findstr "Thread"
110114
```
111115
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+.
113117

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`.
115119

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:
117121

118122
```cmd
119123
php -i | find "extension_dir"
120124
```
121125

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.
123127

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:
125129

126130
```cmd
127131
php -i | find "Loaded Configuration File"
128132
```
129133

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:
131137

132-
Under the Dynamic Extensions section:
133138
```cmd
134139
extension=mysqlnd_azure
135140
```
136-
137-
Under the Module Settings section:
138-
```cmd
141+
142+
Under the Module Settings section:
143+
144+
```cmd
139145
[mysqlnd_azure]
140146
mysqlnd_azure.enableRedirect = on/off/preferred
141147
```
142148

143149
### Confirm redirection
144150

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.
152+
147153
```php
148154
<?php
149155
$host = '<yourservername>.mysql.database.azure.com';
@@ -152,7 +158,7 @@ $password = '<yourpassword>';
152158
$db_name = 'testdb';
153159
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
154160
$db = mysqli_init();
155-
//The connection must be configured with SSL for redirection test
161+
//The connection must be configured with SSL for the redirection test
156162
$link = mysqli_real_connect ($db, $host, $username, $password, $db_name, 3306, NULL, MYSQLI_CLIENT_SSL);
157163
if (!$link) {
158164
die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n");
@@ -167,4 +173,5 @@ $db_name = 'testdb';
167173
```
168174
169175
## Next steps
170-
For more information about connection strings, see [Connection Strings](how-to-connection-string.md).
176+
177+
- For more information about connection strings, see [Connection Strings](how-to-connection-string.md).

0 commit comments

Comments
 (0)