Reputation: 145
I am new to Azure CLI. I was trying out some commands to get a list of all database present in the Azure account from CLI.
I have used this command to get the information
az mysql db list --resource-group --server-name
But I want to find the list of all databases without giving any details(For eg. Resource group name and server name.)
I am trying to write a shell scripting but nothing is working.
Upvotes: 2
Views: 8988
Reputation: 168
This one gives you all Single Instance servers and Flexible servers at once using az graph query:
az graph query -q "Resources | where type has 'Microsoft.DBforMySQL' | project id, type, subscriptionId"
Upvotes: 1
Reputation: 11
To extract all databases in all MSSQL servers in the subscription I use this command:
az sql db list --ids $(az sql server list --query [].id -o tsv)
could you try something like this for mysql.
Upvotes: 1
Reputation: 423
az mysql server list
or you can run az resource list and then filter the output for example
az resource list -o table --query "[?type=='Microsoft.DBforMySQL/servers'].[name,resourceGroup]"
or for a more elegant output:
az resource list -o table --query "[?type=='Microsoft.DBforMySQL/servers'].{name:name, group:resourceGroup}"
If you are using powershell
az resource list -o table | select-string 'Microsoft.DBforMySQL/servers'
Or grep for Linux/mac
az resource list -o table | grep 'Microsoft.DBforMySQL/servers'
for-o (--output) you can use 'table', 'tsv' or 'jsonc'
Upvotes: 3
Reputation: 12768
Note: You can configure the default group, but server name required to provide every time.
az mysql db list
Arguments:
--server-name -s [Required]: The name of the server
--resource-group -g : Name of resource group
You can configure the default group using az configure --defaults group=name
For more details, refer "az mysql db".
Upvotes: 1