使用 Azure CLI 列出和更新 Azure Database for MariaDB 服务器的配置List and update configurations of an Azure Database for MariaDB server using Azure CLI

此示例 CLI 脚本列出了 Azure Database for MariaDB 服务器的可用配置参数及其允许的值,并将 innodb_lock_wait_timeout 设置为默认值以外的值。This sample CLI script lists all available configuration parameters as well as their allowable values for Azure Database for MariaDB server, and sets the innodb_lock_wait_timeout to a value that is other than the default one.

本文需要 Azure CLI 2.0 或更高版本。This article requires Azure CLI version 2.0 or later. 通过运行 az --version 来查看版本。Check the version by running az --version. 请参阅安装 Azure CLI,了解如何安装或升级 Azure CLI 的版本。See Install Azure CLI to install or upgrade your version of Azure CLI.

示例脚本Sample script

在此示例脚本中,编辑突出显示的行,将管理员用户名和密码更新为你自己的。In this sample script, edit the highlighted lines to update the admin username and password to your own.

#!/bin/bash

# Create a resource group
az group create \
--name myresourcegroup \
--location chinaeast2

# Create a MariaDB server in the resource group
# Name of a server maps to DNS name and is thus required to be globally unique in Azure.
# Substitute the <server_admin_password> with your own value.
az mariadb server create \
--name mydemoserver \
--resource-group myresourcegroup \
--location chinaeast2 \
--admin-user myadmin \
--admin-password <server_admin_password> \
--sku-name GP_Gen5_2 \

# Display all available configurations with valid values of an Azure Database for MariaDB server
az mariadb server configuration list \
--resource-group myresourcegroup \
--server-name mydemoserver

# Set value of *innodb_lock_wait_timeout*
az mariadb server configuration set \
--resource-group myresourcegroup \
--server-name mydemoserver \
--name innodb_lock_wait_timeout \
--value 120

# Check the value of *innodb_lock_wait_timeout*
az mariadb server configuration show \
--resource-group myresourcegroup \
--server-name mydemoserver \
--name innodb_lock_wait_timeout

清理部署Clean up deployment

运行脚本示例后,请使用以下命令删除资源组以及与其关联的所有资源。Use the following command to remove the resource group and all resources associated with it after the script has been run.

#!/bin/bash
az group delete --name myresourcegroup

脚本说明Script explanation

此脚本使用下表中列出的命令:This script uses the commands outlined in the following table:

命令Command 说明Notes
az group createaz group create 创建用于存储所有资源的资源组。Creates a resource group in which all resources are stored.
az mariadb server createaz mariadb server create 创建用于托管数据库的 MariaDB 服务器。Creates a MariaDB server that hosts the databases.
az mariadb server configuration listaz mariadb server configuration list 列出 Azure Database for MariaDB 服务器的配置。List the configurations of an Azure Database for MariaDB server.
az mariadb server configuration setaz mariadb server configuration set 更新 Azure Database for MariaDB 服务器的配置。Update the configuration of an Azure Database for MariaDB server.
az mariadb server configuration showaz mariadb server configuration show 显示 Azure Database for MariaDB 服务器的配置。Show the configuration of an Azure Database for MariaDB server.
az group deleteaz group delete 删除资源组,包括所有嵌套的资源。Deletes a resource group including all nested resources.

后续步骤Next steps