使用 CLI 在 Azure SQL 数据库中缩放弹性池Use CLI to scale an elastic pool in Azure SQL Database

此 Azure CLI 脚本示例创建弹性池、移动共用数据库,并更改弹性池计算大小。This Azure CLI script example creates elastic pools, moves pooled databases, and changes elastic pool compute sizes.

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

本主题需要运行 Azure CLI 版本 2.0 或更高版本。This topic requires that you are running the Azure CLI version 2.0 or later. 运行 az --version 即可查找版本。Run az --version to find the version. 如需进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install the Azure CLI.

示例脚本Sample script

#!/bin/bash

# Set an admin login and password for your database
export adminlogin=ServerAdmin
export password=ChangeYourAdminPassword1
# the logical server name has to be unique in the system
export servername=server-$RANDOM

# Create a resource group
az group create \
    --name myResourceGroup \
    --location "China East" 

# Create a server
az sql server create \
    --name $servername \
    --resource-group myResourceGroup \
    --location "China East" \
    --admin-user $adminlogin \
    --admin-password $password

# Create a pool
az sql elastic-pools create \
    --resource-group myResourceGroup \
    --location "China East"  \
    --server $servername \
    --name samplepool \
    --dtu 50 \
    --database-dtu-max 20

# Create two database in the pool
az sql db create \
    --resource-group myResourceGroup \
    --server $servername \
    --name myFirstSampleDatabase \
    --elastic-pool-name samplepool
az sql db create \
    --resource-group myResourceGroup \
    --server $servername \
    --name mySecondSampleDatabase \
    --elastic-pool-name samplepool

# Scale up to the pool to 100 eDTU
az sql elastic-pools update \
    --resource-group myResourceGroup \
    --server $servername \
    --name samplepool \
    --set dtu=100

清理部署Clean up deployment

使用以下命令删除资源组及其相关的所有资源。Use the following command to remove the resource group and all resources associated with it.

az group delete --name myResourceGroup

脚本说明Script explanation

此脚本使用以下命令创建资源组、SQL 数据库服务器、单一数据库和 SQL 数据库防火墙规则。This script uses the following commands to create a resource group, SQL Database server, single database, and SQL Database firewall rules. 表中的每条命令均链接到特定于命令的文档。Each command in the table links to command specific documentation.

命令Command 注释Notes
az group createaz group create 创建用于存储所有资源的资源组。Creates a resource group in which all resources are stored.
az sql server createaz sql server create 创建托管单一数据库和弹性池的 SQL 数据库服务器。Creates a SQL Database server that hosts single databases and elastic pools.
az sql elastic-pools createaz sql elastic-pools create 创建弹性池。Creates an elastic pool.
az sql db createaz sql db create 创建单一数据库或共用数据库。Creates a single or pooled database.
az sql elastic-pools updateaz sql elastic-pools update 更新弹性池,在此示例中更改分配的 eDTU。Updates an elastic pool, in this example changes the assigned eDTU.
az group deleteaz group delete 删除资源组,包括所有嵌套的资源。Deletes a resource group including all nested resources.

后续步骤Next steps

有关 Azure CLI 的详细信息,请参阅 Azure CLI 文档For more information on the Azure CLI, see Azure CLI documentation.

其他 SQL 数据库 CLI 脚本示例可以在 Azure SQL 数据库文档中找到。Additional SQL Database CLI script samples can be found in the Azure SQL Database documentation.