排查 Azure Databases for MySQL 的连接问题Troubleshoot connection issues to Azure Database for MySQL

Note

将要查看的是 Azure Database for MySQL 的新服务。You are viewing the new service of Azure Database for MySQL. 若要查看经典 MySQL Database for Azure 的文档,请访问此页To view the documentation for classic MySQL Database for Azure, please visit this page.

连接问题可能由多种因素造成,包括:Connection problems may be caused by a variety of things, including:

  • 防火墙设置Firewall settings
  • 连接超时Connection time-out
  • 不正确的登录信息Incorrect login information
  • 某些 Azure Database for MySQL 资源达到了最大限制Maximum limit reached on some Azure Database for MySQL resources
  • 服务的基础结构出现问题Issues with the infrastructure of the service
  • 正在服务中执行维护Maintenance being performed in the service
  • 通过缩放 vCore 数目或移到不同的服务层级更改了服务器的计算资源分配The compute allocation of the server is changed by scaling the number of vCores or moving to a different service tier

通常,Azure Database for MySQL 的连接问题可按如下方式分类:Generally, connection issues to Azure Database for MySQL can be classified as follows:

  • 暂时性错误(短暂或间歇性)Transient errors (short-lived or intermittent)
  • 持久或非暂时性错误(定期重复发生的错误)Persistent or non-transient errors (errors that regularly recur)

对暂时性错误进行故障排除Troubleshoot transient errors

在执行维护、系统遇到硬件或软件错误,或更改服务器的 vCore 数目或服务层级时,会发生暂时性错误。Transient errors occur when maintenance is performed, the system encounters an error with the hardware or software, or you change the vCores or service tier of your server. Azure Database for MySQL 服务具有内置的高可用性,可以自动缓解此类问题。The Azure Database for MySQL service has built-in high availability and is designed to mitigate these types of problems automatically. 但是,应用程序会短暂地与服务器断开连接,通常不会超过 60 秒。However, your application loses its connection to the server for a short period of time of typically less than 60 seconds at most. 某些事件偶尔可能需要更长的时间才能缓解,例如,当某个大型事务导致恢复长时间运行时。Some events can occasionally take longer to mitigate, such as when a large transaction causes a long-running recovery.

解决暂时性连接问题的步骤Steps to resolve transient connectivity issues

  1. 检查 Azure 服务仪表板,了解在由应用程序报告错误期间是否发生任何已知的服务中断。Check the Azure Service Dashboard for any known outages that occurred during the time in which the errors were reported by the application.
  2. 连接到云服务的应用程序(例如 Azure Database for MySQL)应预料到会发生暂时性错误,并实施重试逻辑来处理这些错误,而不是将它们作为应用程序错误展现给用户。Applications that connect to a cloud service such as Azure Database for MySQL should expect transient errors and implement retry logic to handle these errors instead of surfacing these as application errors to users. 查看处理 Azure Database for MySQL 的暂时性连接错误,了解有关处理暂时性错误的最佳做法和设计准则。Review Handling of transient connectivity errors for Azure Database for MySQL for best practices and design guidelines for handling transient errors.
  3. 由于服务器即将达到其资源限制,错误可能看起来像是暂时性连接问题。As a server approaches its resource limits, errors can seem to be transient connectivity issue. 请参阅 Azure Database for MySQL 中的限制See Limitations in Azure Database for MySQL.
  4. 如果连接问题继续存在,或者应用程序发生错误的持续时间超过 60 秒或在特定的一天中看到错误多次发生,请通过 Azure 支持站点提出 Azure 支持请求。If connectivity problems continue, or if the duration for which your application encounters the error exceeds 60 seconds or if you see multiple occurrences of the error in a given day, file an Azure support request by the Azure Support site.

排查一再出现的错误Troubleshoot persistent errors

如果应用程序一直无法连接到 Azure Database for MySQL,通常表示下列其中一项出现了问题:If the application persistently fails to connect to Azure Database for MySQL, it usually indicates an issue with one of the following:

  • 服务器防火墙配置:请确保 Azure Database for MySQL 服务器防火墙配置为允许来自客户端(包括代理服务器和网关)的连接。Server firewall configuration: Make sure that the Azure Database for MySQL server firewall is configured to allow connections from your client, including proxy servers and gateways.
  • 客户端防火墙配置:客户端的防火墙必须允许连接到数据库服务器。Client firewall configuration: The firewall on your client must allow connections to your database server. 不能访问的服务器的 IP 地址和端口以及一些防火墙中的应用程序名称(如 MySQL)必须被允许。IP addresses and ports of the server that you cannot to must be allowed as well as application names such as MySQL in some firewalls.
  • 用户失误:例如,你可能错误键入了连接参数(例如,在连接字符串中键入了服务器名称,或者在用户名中遗漏了 @servername 后缀)。User error: You might have mistyped connection parameters, such as the server name in the connection string or a missing @servername suffix in the user name.

解决永久性连接问题的步骤Steps to resolve persistent connectivity issues

  1. 设置防火墙规则以允许客户端 IP 地址。Set up firewall rules to allow the client IP address. (仅出于临时测试目的)使用 0.0.0.0 作为起始 IP 地址,使用 255.255.255.255 作为结束 IP 地址,来设置一个防火墙规则。For temporary testing purposes only, set up a firewall rule using 0.0.0.0 as the starting IP address and using 255.255.255.255 as the ending IP address. 这样会使服务器向所有 IP 地址开放。This will open the server to all IP addresses. 如果这样可以解决连接性问题,请删除此规则,再针对适当限制的 IP 地址或地址范围创建防火墙规则。If this resolves your connectivity issue, remove this rule and create a firewall rule for an appropriately limited IP address or address range.
  2. 在客户端与 Internet 之间的所有防火墙上,确保为出站连接打开端口 3306。On all firewalls between the client and the internet, make sure that port 3306 is open for outbound connections.
  3. 验证连接字符串和其他连接设置。Verify your connection string and other connection settings. 查看如何将应用程序连接到 Azure Database for MySQLReview How to connect applications to Azure Database for MySQL.
  4. 在仪表板中检查服务运行状况。Check the service health in the dashboard. 如果你认为发生了区域性服务中断,请参阅有关使用 Azure Database for MySQL 确保业务连续性的概述了解恢复到新区域所要执行的步骤。If you think there's a regional outage, see Overview of business continuity with Azure Database for MySQL for steps to recover to a new region.

后续步骤Next steps