从 Azure 门户配置和访问 Azure Database for Maria DB 慢查询日志Configure and access Azure Database for Maria DB slow query logs from the Azure portal

可以从 Azure 门户配置、列出并下载 Azure Database for MariaDB 慢查询日志You can configure, list, and download the Azure Database for MariaDB slow query logs from the Azure portal.

先决条件Prerequisites

本文中的步骤要求具备 Azure Database for MariaDB 服务器The steps in this article require that you have Azure Database for MariaDB server.

配置日志记录Configure logging

配置慢查询日志的访问权限。Configure access to the slow query log.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 选择 Azure Database for MariaDB 服务器。Select your Azure Database for MariaDB server.

  3. 在边栏中的“监视”部分下,选择“服务器日志” 。Under the Monitoring section in the sidebar, select Server logs. “服务器日志”选项的屏幕截图Screenshot of Server logs options

  4. 若要查看服务器参数,请选择“单击此处以启用日志并配置日志参数” 。To see the server parameters, select Click here to enable logs and configure log parameters.

  5. 打开“slow_query_log” 的开关 。Turn slow_query_log to ON.

  6. 使用 log_output 选择要将日志输出到的位置。Select where to output the logs to using log_output. 若要将日志同时发送到本地存储和 Azure Monitor 诊断日志,请选择“File” 。To send logs to both local storage and Azure Monitor Diagnostic Logs, select File.

  7. 更改所需的任何其他参数。Change any other parameters needed.

  8. 选择“保存” 。Select Save.

    显示慢查询日志参数和“保存”的屏幕截图。

在“服务器参数” 页上,可以通过关闭该页来返回到日志列表。From the Server Parameters page, you can return to the list of logs by closing the page.

查看列表并下载日志View list and download logs

日志记录开始后,可以查看可用慢查询日志列表,并下载单个日志文件。After logging begins, you can view a list of available slow query logs, and download individual log files.

  1. 打开 Azure 门户。Open the Azure portal.

  2. 选择 Azure Database for MariaDB 服务器。Select your Azure Database for MariaDB server.

  3. 在边栏中的“监视”部分下,选择“服务器日志” 。Under the Monitoring section in the sidebar, select Server logs. 此页将显示日志文件列表。The page shows a list of your log files.

    “服务器日志”页的屏幕截图,其中突出显示了日志列表

    提示

    日志命名约定是 mysql-slow-< your server name>-yyyymmddhh.log 。The naming convention of the log is mysql-slow-< your server name>-yyyymmddhh.log. 文件名中使用的日期和时间是发布日志的时间。The date and time used in the file name is the time when the log was issued. 日志文件每 24 小时或每 7.5 GB 轮换一次(以先达到的条件为准)。Log files are rotated every 24 hours or 7.5 GB, whichever comes first.

  4. 如果需要,可使用搜索框快速缩小范围,以根据日期和时间找到特定日志。If needed, use the search box to quickly narrow down to a specific log, based on date and time. 搜索按日志名称进行。The search is on the name of the log.

  5. 若要下载单个日志文件,请选择表行中每个日志文件旁边的向下箭头图标。To download individual log files, select the down-arrow icon next to each log file in the table row.

    “服务器日志”页的屏幕截图,其中突出显示了向下箭头图标

设置诊断日志Set up diagnostic logs

  1. 在边栏中的“监视” 部分下,选择“诊断设置” > “添加诊断设置” 。Under the Monitoring section in the sidebar, select Diagnostic settings > Add diagnostic setting.

    “诊断设置”选项的屏幕截图

  2. 提供诊断设置名称。Provide a diagnostic setting name.

  3. 指定向哪些数据接收器(存储帐户、事件中心或 Log Analytics 工作区)发送慢查询日志。Specify which data sinks to send the slow query logs (storage account, event hub, or Log Analytics workspace).

  4. 选择 MySqlSlowLogs 作为日志类型。Select MySqlSlowLogs as the log type. “诊断设置配置”选项的屏幕截图Screenshot of Diagnostic settings configuration options

  5. 配置可以通过管道向其传送慢查询日志的数据接收器后,选择“保存”。 After you've configured the data sinks to pipe the slow query logs to, select Save. “诊断设置配置”选项的屏幕截图,其中突出显示了“保存”Screenshot of Diagnostic settings configuration options, with Save highlighted

  6. 可以通过在配置的数据接收器中浏览慢查询日志来对其进行访问。Access the slow query logs by exploring them in the data sinks you configured. 最多需要等待 10 分钟的时间,这些日志就会出现。It can take up to 10 minutes for the logs to appear.

后续步骤Next steps

  • 若要了解如何以编程方式下载慢查询日志,请参阅在 CLI 中访问慢查询日志See Access slow query logs in CLI to learn how to download slow query logs programmatically.
  • 详细了解 Azure Database for MariaDB 中的慢查询日志Learn more about slow query logs in Azure Database for MariaDB.
  • 有关参数定义和日志记录的详细信息,请参阅日志上的 MariaDB 文档。For more information about the parameter definitions and logging, see the MariaDB documentation on logs.