使用 Azure CLI 配置和访问 Azure Database for Maria DB 慢查询日志Configure and access Azure Database for Maria DB slow query logs by using Azure CLI
08/17/2020
本文内容
可以使用 Azure CLI(Azure 命令行实用工具)下载 Azure Database for MariaDB 慢查询日志。You can download the Azure Database for MariaDB slow query logs by using Azure CLI, the Azure command-line utility.
先决条件Prerequisites
若要逐步执行本操作方法指南,需要:To step through this how-to guide, you need:
配置日志记录Configure logging
通过执行下列步骤,可以对服务器进行配置以访问 MariaDB 慢查询日志:You can configure the server to access the MariaDB slow query log by taking the following steps:
通过将 slow_query_log 参数设置为 ON 启用慢查询日志记录。Turn on slow query logging by setting the slow_query_log parameter to ON.
使用 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. 若要仅将日志发送到 Azure Monitor 日志,请选择“None”To send logs only to Azure Monitor Logs, select None
调整其他参数,例如 long_query_time 和 log_slow_admin_statements 。Adjust other parameters, such as long_query_time and log_slow_admin_statements.
若要了解如何通过 Azure CLI 设置这些参数的值,请参阅如何配置服务器参数。To learn how to set the value of these parameters through Azure CLI, see How to configure server parameters.
例如,以下 CLI 命令将启用慢查询日志、将长查询时间设置为 10 秒并禁用慢管理语句的日志记录。For example, the following CLI command turns on the slow query log, sets the long query time to 10 seconds, and then turns off the logging of the slow admin statement. 最后,它将列出配置选项供复查。Finally, it lists the configuration options for your review.
az mariadb server configuration set --name slow_query_log --resource-group myresourcegroup --server mydemoserver --value ON
az mariadb server configuration set --name log_output --resource-group myresourcegroup --server mydemoserver --value FILE
az mariadb server configuration set --name long_query_time --resource-group myresourcegroup --server mydemoserver --value 10
az mariadb server configuration set --name log_slow_admin_statements --resource-group myresourcegroup --server mydemoserver --value OFF
az mariadb server configuration list --resource-group myresourcegroup --server mydemoserver
列出 Azure Database for MariaDB 服务器的日志List logs for Azure Database for MariaDB server
如果“log_output” 配置为“File”,则可以直接从服务器的本地存储访问日志。If log_output is configured to "File", you can access logs directly from the server's local storage. To list the available slow query log files for your server, run the az mariadb server-logs list command.
可以列出资源组 myresourcegroup 下的服务器 mydemoserver.mariadb.database.chinacloudapi.cn 的日志文件。You can list the log files for server mydemoserver.mariadb.database.chinacloudapi.cn under the resource group myresourcegroup. 然后在日志文件列表中找到名为“log_files_list.txt”的文本文件 。Then direct the list of log files to a text file called log_files_list.txt.
az mariadb server-logs list --resource-group myresourcegroup --server mydemoserver > log_files_list.txt
从服务器下载日志Download logs from the server
如果“log_output” 配置为“File”,则可以使用 az mariadb server-logs download 命令从服务器下载单个日志文件。If log_output is configured to "File", you can download individual log files from your server with the az mariadb server-logs download command.
使用以下示例,可以将资源组 myresourcegroup 下服务器 mydemoserver.mariadb.database.chinacloudapi.cn 的特定日志文件下载到本地环境。Use the following example to download the specific log file for the server mydemoserver.mariadb.database.chinacloudapi.cn under the resource group myresourcegroup to your local environment.
az mariadb server-logs download --name mysql-slow-mydemoserver-2018110800.log --resource-group myresourcegroup --server mydemoserver
后续步骤Next steps