Azure Database for MySQL CLI Commands
This page provides a comprehensive guide to managing Azure Database for MySQL instances using the Azure Command-Line Interface (CLI).
Core Concepts
The Azure CLI offers a powerful set of commands for interacting with Azure resources. For Azure Database for MySQL, you can perform operations such as:
- Creating and deleting servers.
- Configuring server parameters.
- Managing firewalls and virtual network rules.
- Scaling compute and storage.
- Backing up and restoring databases.
Getting Started
Ensure you have the Azure CLI installed and are logged in to your Azure account. You can verify your installation with:
az --version
And log in with:
az login
Managing MySQL Servers
Creating a Server
To create a new Azure Database for MySQL server, use the az mysql server create
command. You need to specify a unique server name, resource group, location, and SKU (pricing tier).
az mysql server create --resource-group MyResourceGroup --name my-mysql-server-001 --location eastus --sku-name B_Gen5_2 --admin-user myadmin --admin-password mypassword
MyResourceGroup
, my-mysql-server-001
, eastus
, B_Gen5_2
, myadmin
, and mypassword
with your desired values.
Listing Servers
To view all MySQL servers in your subscription or a specific resource group:
az mysql server list
az mysql server list --resource-group MyResourceGroup
Showing Server Details
Get detailed information about a specific MySQL server:
az mysql server show --resource-group MyResourceGroup --name my-mysql-server-001
Deleting a Server
To remove a MySQL server and all its associated data:
az mysql server delete --resource-group MyResourceGroup --name my-mysql-server-001
Configuring Server Parameters
You can adjust various server parameters to optimize performance or meet specific requirements.
Listing Parameters
View the current server parameters:
az mysql server parameter list --resource-group MyResourceGroup --server-name my-mysql-server-001
Updating Parameters
Modify a specific server parameter, for example, to increase the max_connections
limit:
az mysql server parameter set --resource-group MyResourceGroup --server-name my-mysql-server-001 --name max_connections --value 200
Managing Firewall Rules
Control network access to your MySQL server by creating firewall rules.
Creating a Firewall Rule
Allow access from a specific IP address:
az mysql server firewall-rule create --resource-group MyResourceGroup --server-name my-mysql-server-001 --name AllowMyIP --start-ip-address 203.0.113.1 --end-ip-address 203.0.113.1
Allow access from an IP address range:
az mysql server firewall-rule create --resource-group MyResourceGroup --server-name my-mysql-server-001 --name AllowMyIPRange --start-ip-address 203.0.113.0 --end-ip-address 203.0.113.255
Allow all Azure services to access the server:
az mysql server firewall-rule create --resource-group MyResourceGroup --server-name my-mysql-server-001 --name AllowAllWindowsAzureIps --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
Listing Firewall Rules
az mysql server firewall-rule list --resource-group MyResourceGroup --server-name my-mysql-server-001
Deleting a Firewall Rule
az mysql server firewall-rule delete --resource-group MyResourceGroup --server-name my-mysql-server-001 --name AllowMyIP
Backups and Restores
Azure Database for MySQL automatically backs up your server. You can also perform manual backups and restore your server to a point in time.
Creating a Manual Backup
az mysql server backup create --resource-group MyResourceGroup --server-name my-mysql-server-001 --name mybackup
Restoring a Server
Restore your server to a specific point in time. A new server will be created with the data from that point.
az mysql server restore --resource-group MyResourceGroup --name my-mysql-server-001 --restore-point-in-time "2023-10-27T10:30:00Z" --target-server my-mysql-server-restored
--target-server
is a new server name that will be created.
Further Information
For a complete list of Azure CLI commands for Azure Database for MySQL, refer to the official Azure CLI documentation.