Quickstart: Use an ARM template to create an Azure Database for MySQL server

APPLIES TO: Azure Database for MySQL - Single Server

Important

Azure Database for MySQL - Single Server is on the retirement path. We strongly recommend for you to upgrade to Azure Database for MySQL - Flexible Server. For more information about migrating to Azure Database for MySQL - Flexible Server, see What's happening to Azure Database for MySQL Single Server?

Azure Database for MySQL is a managed service that you use to run, manage, and scale highly available MySQL databases in the cloud. In this quickstart, you use an Azure Resource Manager template (ARM template) to create an Azure Database for MySQL server with virtual network integration. You can create the server in the Azure portal, Azure CLI, or Azure PowerShell.

A resource manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. In declarative syntax, you describe your intended deployment without writing the sequence of programming commands to create the deployment.

If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.

Deploy to Azure button

Prerequisites

An Azure account with an active subscription. Create one for free.

Review the template

You create an Azure Database for MySQL server with a defined set of compute and storage resources. To learn more, see Azure Database for MySQL pricing tiers. You create the server within an Azure resource group.

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",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.5.6.12127",
      "templateHash": "7949891959208359208"
    }
  },
  "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",
      "allowedValues": [
        "Basic",
        "GeneralPurpose",
        "MemoryOptimized"
      ],
      "metadata": {
        "description": "Azure database for MySQL pricing tier"
      }
    },
    "skuFamily": {
      "type": "string",
      "defaultValue": "Gen5",
      "metadata": {
        "description": "Azure database for MySQL sku family"
      }
    },
    "mysqlVersion": {
      "type": "string",
      "defaultValue": "8.0",
      "allowedValues": [
        "5.6",
        "5.7",
        "8.0"
      ],
      "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": [
      {
        "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": [
    {
      "type": "Microsoft.DBforMySQL/servers/virtualNetworkRules",
      "apiVersion": "2017-12-01",
      "name": "[format('{0}/{1}', parameters('serverName'), parameters('virtualNetworkRuleName'))]",
      "properties": {
        "virtualNetworkSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]",
        "ignoreMissingVnetServiceEndpoint": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.DBforMySQL/servers', parameters('serverName'))]",
        "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]"
      ]
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2021-05-01",
      "name": "[parameters('virtualNetworkName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('vnetAddressPrefix')]"
          ]
        }
      }
    },
    {
      "type": "Microsoft.Network/virtualNetworks/subnets",
      "apiVersion": "2021-05-01",
      "name": "[format('{0}/{1}', parameters('virtualNetworkName'), parameters('subnetName'))]",
      "properties": {
        "addressPrefix": "[parameters('subnetPrefix')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]"
      ]
    },
    {
      "type": "Microsoft.DBforMySQL/servers",
      "apiVersion": "2017-12-01",
      "name": "[parameters('serverName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('skuName')]",
        "tier": "[parameters('SkuTier')]",
        "capacity": "[parameters('skuCapacity')]",
        "size": "[format('{0}', parameters('SkuSizeMB'))]",
        "family": "[parameters('skuFamily')]"
      },
      "properties": {
        "createMode": "Default",
        "version": "[parameters('mysqlVersion')]",
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
        "storageProfile": {
          "storageMB": "[parameters('SkuSizeMB')]",
          "backupRetentionDays": "[parameters('backupRetentionDays')]",
          "geoRedundantBackup": "[parameters('geoRedundantBackup')]"
        }
      }
    },
    {
      "copy": {
        "name": "firewallRules",
        "count": "[length(variables('firewallrules'))]",
        "mode": "serial",
        "batchSize": 1
      },
      "type": "Microsoft.DBforMySQL/servers/firewallRules",
      "apiVersion": "2017-12-01",
      "name": "[format('{0}/{1}', parameters('serverName'), variables('firewallrules')[copyIndex()].Name)]",
      "properties": {
        "startIpAddress": "[variables('firewallrules')[copyIndex()].StartIpAddress]",
        "endIpAddress": "[variables('firewallrules')[copyIndex()].EndIpAddress]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.DBforMySQL/servers', parameters('serverName'))]"
      ]
    }
  ]
}

The template defines five Azure resources:

More Azure Database for MySQL template samples can be found in the quickstart template gallery.

Deploy the template

Select the following link to deploy the Azure Database for MySQL server template in the Azure portal:

Deploy to Azure in portal

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.

    Deploy Azure Database for MySQL with VNet window, Azure quickstart template, Azure portal

  4. Change the other default settings if you want:

    • Subscription: the Azure subscription you want to use for the server.
    • Sku Capacity: the vCore capacity, which can be 2 (the default), 4, 8, 16, 32, or 64.
    • 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 Size MB: the storage size, in megabytes, of the Azure Database for MySQL server (default 5120).
    • Sku Tier: the deployment tier, such as Basic, GeneralPurpose (the default), or MemoryOptimized.
    • Sku Family: Gen4 or Gen5 (the default), which indicates hardware generation for server deployment.
    • Mysql Version: the version of MySQL server to deploy, such as 5.6 or 5.7 (the default).
    • Backup Retention Days: the desired period for geo-redundant backup retention, in days (default 7).
    • Geo Redundant Backup: Enabled or Disabled (the default), depending on geo-disaster recovery (Geo-DR) requirements.
    • Virtual Network Name: the name of the virtual network (default azure_mysql_vnet).
    • Subnet Name: the name of the subnet (default azure_mysql_subnet).
    • Virtual Network Rule Name: the name of the virtual network rule allowing the subnet (default AllowSubnet).
    • Vnet Address Prefix: the address prefix for the virtual network (default 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

Follow these steps to see an overview of your new Azure Database for MySQL server:

  1. In the Azure portal, search for and select Azure Database for MySQL servers.

  2. In the database list, select your new server. The Overview page for your new Azure Database for MySQL server appears.

Exporting ARM template from the portal

You can export an ARM template from the Azure portal. There are two ways to export a template:

When exporting the template, in the "properties":{ } section of the MySQL server resource you will notice that administratorLogin and administratorLoginPassword will not be included for security reasons. You MUST add these parameters to your template before deploying the template or the template will fail.

"resources": [
    {
      "type": "Microsoft.DBforMySQL/servers",
      "apiVersion": "2017-12-01",
      "name": "[parameters('servers_name')]",
      "location": "southcentralus",
      "sku": {
                "name": "B_Gen5_1",
                "tier": "Basic",
                "family": "Gen5",
                "capacity": 1
            },
      "properties": {
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",

Clean up resources

When it's no longer needed, delete the resource group, which deletes the resources in the resource group.

  1. 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

For a step-by-step tutorial that guides you through the process of creating an ARM template, see: