|
| 1 | +--- |
| 2 | +title: Manage read replicas - Azure PowerShell - Azure Database for MySQL |
| 3 | +description: Learn how to set up and manage read replicas in Azure Database for MySQL using PowerShell. |
| 4 | +author: ajlam |
| 5 | +ms.author: andrela |
| 6 | +ms.service: mysql |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 4/29/2020 |
| 9 | +--- |
| 10 | + |
| 11 | +# How to create and manage read replicas in Azure Database for MySQL using PowerShell |
| 12 | + |
| 13 | +In this article, you learn how to create and manage read replicas in the Azure Database for MySQL |
| 14 | +service using PowerShell. To learn more about read replicas, see the |
| 15 | +[overview](concepts-read-replicas.md). |
| 16 | + |
| 17 | +## Azure PowerShell |
| 18 | + |
| 19 | +You can create and manage read replicas using PowerShell. |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +To complete this how-to guide, you need: |
| 24 | + |
| 25 | +- The [Az PowerShell module](/powershell/azure/install-az-ps) installed locally or |
| 26 | + [Azure Cloud Shell](https://shell.azure.com/) in the browser |
| 27 | +- An [Azure Database for MySQL server](quickstart-create-mysql-server-database-using-azure-powershell.md) |
| 28 | + |
| 29 | +> [!IMPORTANT] |
| 30 | +> While the Az.MySql PowerShell module is in preview, you must install it separately from the Az |
| 31 | +> PowerShell module using the following command: `Install-Module -Name Az.MySql -AllowPrerelease`. |
| 32 | +> Once the Az.MySql PowerShell module is generally available, it becomes part of future Az |
| 33 | +> PowerShell module releases and available natively from within Azure Cloud Shell. |
| 34 | +
|
| 35 | +If you choose to use PowerShell locally, connect to your Azure account using the |
| 36 | +[Connect-AzAccount](/powershell/module/az.accounts/Connect-AzAccount) cmdlet. |
| 37 | + |
| 38 | +[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)] |
| 39 | + |
| 40 | +> [!IMPORTANT] |
| 41 | +> The read replica feature is only available for Azure Database for MySQL servers in the General |
| 42 | +> Purpose or Memory Optimized pricing tiers. Ensure the master server is in one of these pricing |
| 43 | +> tiers. |
| 44 | +
|
| 45 | +### Create a read replica |
| 46 | + |
| 47 | +A read replica server can be created using the following command: |
| 48 | + |
| 49 | +```azurepowershell-interactive |
| 50 | +Get-AzMySqlServer -Name mydemoserver -ResourceGroupName myresourcegroup | |
| 51 | + New-AzMySqlServerReplica -Name mydemoreplicaserver -ResourceGroupName myresourcegroup |
| 52 | +``` |
| 53 | + |
| 54 | +The `New-AzMySqlServerReplica` command requires the following parameters: |
| 55 | + |
| 56 | +| Setting | Example value | Description | |
| 57 | +| --- | --- | --- | |
| 58 | +| ResourceGroupName | myresourcegroup | The resource group where the replica server is created. | |
| 59 | +| Name | mydemoreplicaserver | The name of the new replica server that is created. | |
| 60 | + |
| 61 | +To create a cross region read replica, use the **Location** parameter. The following example creates |
| 62 | +a replica in the **West US** region. |
| 63 | + |
| 64 | +```azurepowershell-interactive |
| 65 | +Get-AzMySqlServer -Name mrdemoserver -ResourceGroupName myresourcegroup | |
| 66 | + New-AzMySqlServerReplica -Name mydemoreplicaserver -ResourceGroupName myresourcegroup -Location westus |
| 67 | +``` |
| 68 | + |
| 69 | +To learn more about which regions you can create a replica in, visit the |
| 70 | +[read replica concepts article](concepts-read-replicas.md). |
| 71 | + |
| 72 | +By default, read replicas are created with the same server configuration as the master unless the |
| 73 | +**Sku** parameter is specified. |
| 74 | + |
| 75 | +> [!NOTE] |
| 76 | +> It is recommended that the replica server's configuration should be kept at equal or greater |
| 77 | +> values than the master to ensure the replica is able to keep up with the master. |
| 78 | +
|
| 79 | +### List replicas for a master server |
| 80 | + |
| 81 | +To view all replicas for a given master server, run the following command: |
| 82 | + |
| 83 | +```azurepowershell-interactive |
| 84 | +Get-AzMySqlReplica -ResourceGroupName myresourcegroup -ServerName mydemoserver |
| 85 | +``` |
| 86 | + |
| 87 | +The `Get-AzMySqlReplica` command requires the following parameters: |
| 88 | + |
| 89 | +| Setting | Example value | Description | |
| 90 | +| --- | --- | --- | |
| 91 | +| ResourceGroupName | myresourcegroup | The resource group where the replica server will be created to. | |
| 92 | +| ServerName | mydemoserver | The name or ID of the master server. | |
| 93 | + |
| 94 | +### Delete a replica server |
| 95 | + |
| 96 | +Deleting a read replica server can be done by running the `Remove-AzMySqlServer` cmdlet. |
| 97 | + |
| 98 | +```azurepowershell-interactive |
| 99 | +Remove-AzMySqlServer -Name mydemoreplicaserver -ResourceGroupName myresourcegroup |
| 100 | +``` |
| 101 | + |
| 102 | +### Delete a master server |
| 103 | + |
| 104 | +> [!IMPORTANT] |
| 105 | +> Deleting a master server stops replication to all replica servers and deletes the master server |
| 106 | +> itself. Replica servers become standalone servers that now support both read and writes. |
| 107 | +
|
| 108 | +To delete a master server, you can run the `Remove-AzMySqlServer` cmdlet. |
| 109 | + |
| 110 | +```azurepowershell-interactive |
| 111 | +Remove-AzMySqlServer -Name mydemoserver -ResourceGroupName myresourcegroup |
| 112 | +``` |
| 113 | + |
| 114 | +## Next steps |
| 115 | + |
| 116 | +> [!div class="nextstepaction"] |
| 117 | +> [Restart Azure Database for MySQL server using PowerShell](howto-restart-server-powershell.md) |
0 commit comments