快速入门:使用 ARM 模板创建 Azure Database for MySQL 服务器Quickstart: Use an ARM template to create an Azure Database for MySQL server

Azure Database for MySQL 是一种托管服务,可用于在云中运行、管理和缩放具有高可用性的 MySQL 数据库。Azure Database for MySQL is a managed service that you use to run, manage, and scale highly available MySQL databases in the cloud. 本快速入门介绍了如何使用 Azure 资源管理器模板(ARM 模板)创建一个带有虚拟网络集成的 Azure Database for MySQL 服务器。In this quickstart, you use an Azure Resource Manager template (ARM template) to create an Azure Database for MySQL server with virtual network integration. 可通过 Azure 门户、Azure CLI 或 Azure PowerShell 创建该服务器。You can create the server in the Azure portal, Azure CLI, or Azure PowerShell.

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Azure 门户中会打开模板。The template will open in the Azure portal.

部署到 AzureDeploy to Azure

先决条件Prerequisites

具有活动订阅的 Azure 帐户。An Azure account with an active subscription. 创建一个试用帐户Create one for trial.

查看模板Review the template

你将使用所定义的一组计算和存储资源创建 Azure Database for MySQL 服务器。You create an Azure Database for MySQL server with a defined set of compute and storage resources. 若要了解详细信息,请参阅 Azure Database for MySQL 定价层To learn more, see Azure Database for MySQL pricing tiers. 请在 Azure 资源组中创建该服务器。You create the server within an Azure resource group.

本快速入门中使用的模板来自 Azure 快速启动模板The template used in this quickstart is from Azure Quickstart Templates.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "serverName": {
            "type": "string",
            "metadata": {
                "description": "Server Name for Azure database for MySQL"
            }
        },
        "administratorLogin": {
            "type": "string",
            "minLength": 1,
            "metadata": {
                "description": "Database administrator login name"
            }
        },
        "administratorLoginPassword": {
            "type": "securestring",
            "minLength": 8,
            "metadata": {
                "description": "Database administrator password"
            }
        },
        "skuCapacity": {
            "type": "int",
            "defaultValue": 2,
            "metadata": {
                "description": "Azure database for MySQL compute capacity in vCores (2,4,8,16,32)"
            }
        },
        "skuName": {
            "type": "string",
            "defaultValue": "GP_Gen5_2",
            "metadata": {
                "description": "Azure database for MySQL sku name "
            }
        },
        "SkuSizeMB": {
            "type": "int",
            "defaultValue": 5120,
            "metadata": {
                "description": "Azure database for MySQL Sku Size "
            }
        },
        "SkuTier": {
            "type": "string",
            "defaultValue": "GeneralPurpose",
            "metadata": {
                "description": "Azure database for MySQL pricing tier"
            }
        },
        "skuFamily": {
            "type": "string",
            "defaultValue": "Gen5",
            "metadata": {
                "description": "Azure database for MySQL sku family"
            }
        },
        "mysqlVersion": {
            "type": "string",
            "allowedValues": [
                "5.6",
                "5.7"
            ],
            "defaultValue": "5.7",
            "metadata": {
                "description": "MySQL version"
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Location for all resources."
            }
        },
        "backupRetentionDays": {
            "type": "int",
            "defaultValue": 7,
            "metadata": {
                "description": "MySQL Server backup retention days"
            }
        },
        "geoRedundantBackup": {
            "type": "string",
            "defaultValue": "Disabled",
            "metadata": {
                "description": "Geo-Redundant Backup setting"
            }
        },
        "virtualNetworkName": {
            "type": "string",
            "defaultValue": "azure_mysql_vnet",
            "metadata": {
                "description": "Virtual Network Name"
            }
        },
        "subnetName": {
            "type": "string",
            "defaultValue": "azure_mysql_subnet",
            "metadata": {
                "description": "Subnet Name"
            }
        },
        "virtualNetworkRuleName": {
            "type": "string",
            "defaultValue": "AllowSubnet",
            "metadata": {
                "description": "Virtual Network RuleName"
            }
        },
        "vnetAddressPrefix": {
            "type": "string",
            "defaultValue": "10.0.0.0/16",
            "metadata": {
                "description": "Virtual Network Address Prefix"
            }
        },
        "subnetPrefix": {
            "type": "string",
            "defaultValue": "10.0.0.0/16",
            "metadata": {
                "description": "Subnet Address Prefix"
            }
        }
    },
    "variables": {
        "firewallrules": {
            "batch": {
                "rules": [
                    {
                        "Name": "rule1",
                        "StartIpAddress": "0.0.0.0",
                        "EndIpAddress": "255.255.255.255"
                    },
                    {
                        "Name": "rule2",
                        "StartIpAddress": "0.0.0.0",
                        "EndIpAddress": "255.255.255.255"
                    }
                ]
            }
        }
    },
    "resources": [
        {
            "apiVersion": "2018-06-01",
            "type": "Microsoft.Network/virtualNetworks",
            "name": "[parameters('virtualNetworkName')]",
            "location": "[parameters('location')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[parameters('vnetAddressPrefix')]"
                    ]
                }
            },
            "resources": [
                {
                    "apiVersion": "2018-06-01",
                    "type": "subnets",
                    "location": "[parameters('location')]",
                    "name": "[parameters('subnetName')]",
                    "dependsOn": [
                        "[parameters('virtualNetworkName')]"
                    ],
                    "properties": {
                        "addressPrefix": "[parameters('subnetPrefix')]"
                    }
                }
            ]
        },
        {
            "apiVersion": "2017-12-01",
            "type": "Microsoft.DBforMySQL/servers",
            "location": "[parameters('location')]",
            "name": "[parameters('serverName')]",
            "sku": {
                "name": "[parameters('skuName')]",
                "tier": "[parameters('skuTier')]",
                "capacity": "[parameters('skuCapacity')]",
                "size": "[parameters('skuSizeMB')]",
                "family": "[parameters('skuFamily')]"
            },
            "properties": {
                "version": "[parameters('mysqlVersion')]",
                "administratorLogin": "[parameters('administratorLogin')]",
                "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
                "storageProfile": {
                    "storageMB": "[parameters('skuSizeMB')]",
                    "backupRetentionDays": "[parameters('backupRetentionDays')]",
                    "geoRedundantBackup": "[parameters('geoRedundantBackup')]"
                }
            },
            "resources": [
                {
                    "name": "[parameters('virtualNetworkRuleName')]",
                    "type": "virtualNetworkRules",
                    "apiVersion": "2017-12-01",
                    "properties": {
                        "virtualNetworkSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]",
                        "ignoreMissingVnetServiceEndpoint": true
                    },
                    "dependsOn": [
                        "[concat('Microsoft.DBforMySQL/servers/', parameters('serverName'))]"
                    ]
                }
            ]
        },
        {
            "name": "[concat(parameters('serverName'),'/',variables('firewallrules').batch.rules[copyIndex()].Name)]",
            "type": "Microsoft.DBforMySQL/servers/firewallRules",
            "apiVersion": "2017-12-01",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[concat('Microsoft.DBforMySQL/servers/', parameters('serverName'))]"
            ],
            "copy": {
                "name": "firewallRulesCopy",
                "mode": "Serial",
                "batchSize": 1,
                "count": "[length(variables('firewallrules').batch.rules)]"
            },
            "properties": {
                "StartIpAddress": "[variables('firewallrules').batch.rules[copyIndex()].StartIpAddress]",
                "EndIpAddress": "[variables('firewallrules').batch.rules[copyIndex()].EndIpAddress]"
            }
        }
    ]
}

该模板定义了五个 Azure 资源:The template defines five Azure resources:

可以在快速入门模板库中找到更多 Azure Database for MySQL 模板示例。More Azure Database for MySQL template samples can be found in the quickstart template gallery.

部署模板Deploy the template

选择以下链接以在 Azure 门户中部署 Azure Database for MySQL 服务器模板:Select the following link to deploy the Azure Database for MySQL server template in the Azure portal:

部署到 AzureDeploy to Azure

在“部署具有 VNet 的 Azure Database for MySQL”页上:On the Deploy Azure Database for MySQL with VNet page:

  1. 对于“资源组”,请选择“新建”,输入新资源组的名称,然后选择“确定” 。For Resource group, select Create new, enter a name for the new resource group, and select OK.

  2. 如果你创建了一个新资源组,请为该资源组和新服务器选择一个位置。If you created a new resource group, select a Location for the resource group and the new server.

  3. 输入服务器名称、管理员登录名和管理员登录密码 。Enter a Server Name, Administrator Login, and Administrator Login Password.

    “部署具有 VNet 的 Azure Database for MySQL”窗口,Azure 快速入门模板,Azure 门户

  4. 根据需要更改其他默认设置:Change the other default settings if you want:

    • 订阅:要用于服务器的 Azure 订阅。Subscription: the Azure subscription you want to use for the server.
    • SKU 容量:vCore 容量,值可以是 2(默认值)、4、8、16、32 或 64 。Sku Capacity: the vCore capacity, which can be 2 (the default), 4, 8, 16, 32, or 64.
    • SKU 名称:SKU 层前缀、SKU 系列和 SKU 容量,以下划线联接,例如 B_Gen5_1、GP_Gen5_2(默认值)或 MO_Gen5_32 。Sku Name: the SKU tier prefix, SKU family, and SKU capacity, joined by underscores, such as B_Gen5_1, GP_Gen5_2 (the default), or MO_Gen5_32.
    • SKU 大小(MB) :Azure Database for MySQL 服务器的存储大小,以 MB 为单位(默认值为 5120)。Sku Size MB: the storage size, in megabytes, of the Azure Database for MySQL server (default 5120).
    • SKU 层:部署层,例如“基本”、“常规用途”(默认值)或“内存优化” 。Sku Tier: the deployment tier, such as Basic, GeneralPurpose (the default), or MemoryOptimized.
    • SKU 系列:“Gen4”或“Gen5”(默认值),表示服务器部署的硬件代系 。Sku Family: Gen4 or Gen5 (the default), which indicates hardware generation for server deployment.
    • Mysql 版本:要部署的 MySQL 服务器版本,例如 5.6 或 5.7(默认值) 。Mysql Version: the version of MySQL server to deploy, such as 5.6 or 5.7 (the default).
    • 备份保留天数:异地冗余备份的所需保留期,以天为单位(默认值为 7)。Backup Retention Days: the desired period for geo-redundant backup retention, in days (default 7).
    • 异地冗余备份:“已启用”或“已禁用”(默认值),具体取决于异地灾难恢复 (Geo-DR) 要求 。Geo Redundant Backup: Enabled or Disabled (the default), depending on geo-disaster recovery (Geo-DR) requirements.
    • 虚拟网络名称:虚拟网络的名称(默认值为 azure_mysql_vnet)。Virtual Network Name: the name of the virtual network (default azure_mysql_vnet).
    • 子网名称:子网的名称(默认值为 azure_mysql_subnet)。Subnet Name: the name of the subnet (default azure_mysql_subnet).
    • 虚拟网络规则名称:允许子网的虚拟网络规则的名称(默认值为 AllowSubnet)。Virtual Network Rule Name: the name of the virtual network rule allowing the subnet (default AllowSubnet).
    • VNet 地址前缀:虚拟网络的地址前缀(默认值为 10.0.0.0/16)。Vnet Address Prefix: the address prefix for the virtual network (default 10.0.0.0/16).
    • 子网前缀:子网的地址前缀(默认值为 10.0.0.0/16)。Subnet Prefix: the address prefix for the subnet (default 10.0.0.0/16).
  5. 阅读条款和条件,并选择“我同意上述条款和条件”。Read the terms and conditions, and then select I agree to the terms and conditions stated above.

  6. 选择“购买”。Select Purchase.

查看已部署的资源Review deployed resources

按照以下步骤查看新 Azure Database for MySQL 服务器的概览:Follow these steps to see an overview of your new Azure Database for MySQL server:

  1. Azure 门户中,搜索并选择“Azure Database for MySQL 服务器”。In the Azure portal, search for and select Azure Database for MySQL servers.

  2. 在数据库列表中选择你的新服务器。In the database list, select your new server. 随后会显示新 Azure Database for MySQL 服务器的“概览”页。The Overview page for your new Azure Database for MySQL server appears.

清理资源Clean up resources

如果不再需要该资源组,可以将其删除,这将删除资源组中的资源。When it's no longer needed, delete the resource group, which deletes the resources in the resource group.

  1. Azure 门户中,搜索并选择“资源组”。In the Azure portal, search for and select Resource groups.

  2. 在资源组列表中,选择你的资源组的名称。In the resource group list, choose the name of your resource group.

  3. 在资源组的“概览”页中,选择“删除资源组” 。In the Overview page of your resource group, select Delete resource group.

  4. 在确认对话框中,键入资源组的名称,然后选择“删除”。In the confirmation dialog box, type the name of your resource group, and then select Delete.

后续步骤Next steps

有关引导你完成 ARM 模板创建过程的分步教程,请参阅:For a step-by-step tutorial that guides you through the process of creating an ARM template, see: