Azure Database for MySQL 中的连接体系结构Connectivity architecture in Azure Database for MySQL

本文介绍 Azure Database for MySQL 的连接体系结构,以及如何在 Azure 内部和外部将流量从客户端定向到 Azure Database for MySQL 实例。This article explains the Azure Database for MySQL connectivity architecture as well as how the traffic is directed to your Azure Database for MySQL instance from clients both within and outside Azure.

连接体系结构Connectivity architecture

可以通过网关连接到 Azure Database for MySQL,该网关负责将传入连接路由到服务器在群集中的物理位置。Connection to your Azure Database for MySQL is established through a gateway that is responsible for routing incoming connections to the physical location of your server in our clusters. 下图演示了流量流。The following diagram illustrates the traffic flow.


客户端在连接到数据库时,会获得一个用于连接到网关的连接字符串。As clients connect to the database, they get a connection string, which connects to the gateway. 该网关有一个公共 IP 地址,用于侦听端口 3306。This gateway has a public IP address that listens to port 3306. 在数据库群集中,流量转发到相应的 Azure Database for MySQL。Inside the database cluster, traffic is forwarded to appropriate Azure Database for MySQL. 因此,为了通过某种方式(例如,通过公司网络)连接到服务器,必须打开客户端防火墙,使出站流量能够访问我们的网关。Therefore, in order to connect to your server, such as from corporate networks, it is necessary to open up the client-side firewall to allow outbound traffic to be able to reach our gateways. 下面是一个按区域分类的可供我们的网关使用的 IP 地址的完整列表。Below you can find a complete list of the IP addresses used by our gateways per region.

Azure Database for MySQL 网关 IP 地址Azure Database for MySQL gateway IP addresses

下表列出了所有数据区域的 Azure Database for MySQL 网关的主要 IP 和次要 IP。The following table lists the primary and secondary IPs of the Azure Database for MySQL gateway for all data regions. 主 IP 地址是网关的当前 IP 地址,第二个 IP 地址是主 IP 地址故障时使用的故障转移 IP 地址。The primary IP address is the current IP address of the gateway and the second IP address is a failover IP address in case of failure of the primary. 如前所述,客户应该允许到这两个 IP 地址的出站流量。As mentioned, customers should allow outbound to both the IP addresses. 第二个 IP 地址不侦听任何服务,除非 Azure Database for MySQL 激活该地址,使之接受连接。The second IP address does not listen in on any services until it is activated by Azure Database for MySQL to accept connections.

区域名称Region Name 网关 IP 地址Gateway IP Addresses
中国东部China East
中国东部 2China East 2
中国北部China North
中国北部 2China North 2

连接重定向Connection redirection

Azure Database for MySQL 支持一个额外的连接策略(即“重定向” ),该策略有助于降低客户端应用程序与 MySQL 服务器之间的网络延迟。Azure Database for MySQL supports an additional connection policy, redirection, that helps to reduce network latency between client applications and MySQL servers. 利用此功能,在建立与 Azure Database for MySQL 服务器的初始 TCP 会话后,服务器会将承载 MySQL 服务器的节点的后端地址返回到客户端。With this feature, after the initial TCP session is established to the Azure Database for MySQL server, the server returns the backend address of the node hosting the MySQL server to the client. 此后,所有后续数据包会绕过网关直接流向服务器。Thereafter, all subsequent packets flow directly to the server, bypassing the gateway. 由于数据包会直接流向服务器,因此延迟和吞吐量这两个指标的表现得到了改善。As packets flow directly to the server, latency and throughput have improved performance.

引擎版本为 5.6、5.7 和 8.0 的 Azure Database for MySQL 服务器支持此功能。This feature is supported in Azure Database for MySQL servers with engine versions 5.6, 5.7, and 8.0.

对重定向的支持可通过 Microsoft 开发的 PHP mysqlnd_azure 扩展获得,也可在 PECL 上获得。Support for redirection is available in the PHP mysqlnd_azure extension, developed by Microsoft, and is available on PECL. 有关如何在应用程序中使用重定向的详细信息,请参阅配置重定向一文。See the configuring redirection article for more information on how to use redirection in your applications.


PHP mysqlnd_azure 扩展对重定向的支持目前为预览版。Support for redirection in the PHP mysqlnd_azure extension is currently in preview.

后续步骤Next steps