List and change server parameters of an Azure Database for MySQL - Flexible Server using Azure CLI
This sample CLI script lists all available server parameters as well as their allowable values for Azure Database for MySQL - Flexible Server, and sets the max_connections and global time_zone parameters to values other than the default ones.
If you don't have an Azure subscription, create an Azure free account before you begin. With an Azure free account, you can now try Azure Database for MySQL - Flexible Server for free for 12 months. For more details, see Try Flexible Server for free.
Prerequisites
Use the Bash environment in Azure Cloud Shell. For more information, see Azure Cloud Shell Quickstart - Bash.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you are running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For additional sign-in options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
- This article requires version 2.0 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
Sample script
Edit the highlighted lines in the script with your values for variables.
#!/bin/bash
# Change server parameters for Azure Database for MySQL - Flexible Server
# Set up variables
RESOURCE_GROUP="myresourcegroup"
SERVER_NAME="mydemoserver" # Substitute with preferred name for MySQL Flexible Server.
LOCATION="westus"
ADMIN_USER="mysqladmin"
PASSWORD="" # Enter your server admin password
IP_ADDRESS= # Enter your IP Address for Public Access - https://whatismyipaddress.com
# 1. Create a resource group
az group create \
--name $RESOURCE_GROUP \
--location $LOCATION
# 2. Create a MySQL Flexible server in the resource group
az mysql flexible-server create \
--name $SERVER_NAME \
--resource-group $RESOURCE_GROUP \
--location $LOCATION \
--admin-user $ADMIN_USER \
--admin-password $PASSWORD \
--public-access $IP_ADDRESS
# 3. List all Flexible Server parameters with their values and parameter descriptions
az mysql flexible-server parameter list \
--resource-group $RESOURCE_GROUP \
--server-name $SERVER_NAME
# 4. Set and check parameter values
# Set value of max_connections parameter
az mysql flexible-server parameter set \
--resource-group $RESOURCE_GROUP \
--server-name $SERVER_NAME \
--name max_connections \
--value 250
# Check value of max_connections paramater
az mysql flexible-server parameter show \
--resource-group $RESOURCE_GROUP \
--server-name $SERVER_NAME \
--name max_connections
# Set value of max_connections parameter back to default
az mysql flexible-server parameter set \
--resource-group $RESOURCE_GROUP \
--server-name $SERVER_NAME \
--name max_connections
# Set global level time zone
az mysql flexible-server parameter set \
--resource-group $RESOURCE_GROUP \
--server-name $SERVER_NAME \
--name time_zone \
--value "+02:00"
# Check global level time zone
az mysql flexible-server parameter show \
--resource-group $RESOURCE_GROUP \
--server-name $SERVER_NAME \
--name time_zone
Clean up deployment
After the sample script has been run, the following code snippet can be used to clean up the resources.
#!/bin/bash
RESOURCE_GROUP="myresourcegroup"
SERVER_NAME="mydemoserver" # Enter your server name
# Delete MySQL Flexible Server
az mysql flexible-server delete \
--resource-group $RESOURCE_GROUP
--name $SERVER_NAME
# Optional : Delete resource group
az group delete --name $RESOURCE_GROUP
Script explanation
This script uses the following commands. Each command in the table links to command specific documentation.
| Command | Notes |
|---|---|
| az group create | Creates a resource group in which all resources are stored |
| az mysql flexible-server create | Creates a Flexible Server that hosts the databases. |
| az mysql flexible-server parameter list | Lists the parameter values for a flexible server. |
| az mysql flexible-server parameter set | Updates the parameter of a flexible server. |
| az mysql flexible-server parameter show | Get a specific parameter value for a flexible server. |
| az mysql flexible-server delete | Deletes a Flexible Server. |
| az group delete | Deletes a resource group including all nested resources. |
Next steps
- Try additional scripts: Azure CLI samples for Azure Database for MySQL - Flexible Server
- For more information on the Azure CLI, see Azure CLI documentation.
