你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本文介绍如何使用 Azure CLI 列出和下载 Azure Database for MySQL 灵活服务器日志。
Prerequisites
本文要求在本地运行 Azure CLI 版本 2.39.0 或更高版本。 若要查看安装的版本,请运行 az --version
命令。 如果需要进行安装或升级,请参阅安装 Azure CLI。
You need to sign in to your account using the az login command. Note the id property, which refers to Subscription ID for your Azure account.
az login
使用 az account set 命令选择帐户下的特定订阅。 Make a note of the id value from the az login output to use as the value for subscription argument in the command. 如果有多个订阅,请选择应计费的资源所在的相应订阅。 若要获取所有订阅,请使用 az account list。
az account set --subscription <subscription id>
使用 Azure CLI 列出服务器日志
配置先决条件并连接到订阅后,运行以下命令,列出 Azure Database for MySQL 灵活服务器实例中的服务器日志。 下面是命令输出的详细信息。
az mysql flexible-server server-logs list --resource-group <myresourcegroup> --server-name <serverlogdemo> --out <table>
下面是上述命令的详细信息
LastModifiedTime | Name | ResourceGroup | SizeInKb | TypePropertiesType | Url |
---|---|---|---|---|---|
2022-08-01T11:09:48+00:00 | mysql-slow-serverlogdemo-2022073111.log | myresourcegroup | 10947 | slowlog |
https://00000000000.file.core.windows.net/0000000serverlog/ slowlogs/mysql-slow-serverlogdemo-2022073111.log? |
2022-08-02T11:10:00+00:00 | mysql-slow-serverlogdemo-2022080111.log | myresourcegroup | 10927 | slowlog |
https://00000000000.file.core.windows.net/0000000serverlog/ 慢日志s/mysql-slow-serverlogdemo-2022080111.log? |
2022-08-03T11:10:12+00:00 | mysql-slow-serverlogdemo-2022080211.log | myresourcegroup | 10936 | slowlog |
https://00000000000.file.core.windows.net/0000000serverlog/ slowlog(慢日志)s/mysql-slow-serverlogdemo-2022080211.log? |
2022-08-03T11:12:00+00:00 | mysql-slow-serverlogdemo-2022080311.log | myresourcegroup | 8920 | slowlog |
https://00000000000.file.core.windows.net/0000000serverlog/ slowlogs/mysql-slow-serverlogdemo-2022080311.log? |
此列表显示可用服务器日志的 LastModifiedTime、Name、ResourceGroup、SizeInKb 和下载 URL。
默认的 LastModifiedTime 设置为 72 小时。 若要列出超过 72 小时的文件,请使用 --file-last-written <Time:HH>
标志。
az mysql flexible-server server-logs list --resource-group <myresourcegroup> --server-name <serverlogdemo> --out table --file-last-written <144>
使用 Azure CLI 下载服务器日志
以下命令将上述服务器日志下载到当前目录。
az mysql flexible-server server-logs download --resource-group <myresourcegroup> --server-name <serverlogdemo> --name <mysql-slow-serverlogdemo-2022073111.log>