@@ -25,6 +25,7 @@ Last updated: 2025-05-09
2525- [ How to provision] ( #how-to-provision )
2626- [ How to enable IOPS] ( #how-to-enable-iops )
2727- [ How to Monitor IOPS Scaling] ( #how-to-monitor-iops-scaling )
28+ - [ Azure CLI Script to Enable Autoscale IOPS] ( #azure-cli-script-to-enable-autoscale-iops )
2829
2930</details >
3031
@@ -80,6 +81,57 @@ Last updated: 2025-05-09
8081
8182 https://github.com/user-attachments/assets/19b96128-e37f-40b4-8e23-8a5384bc6686
8283
84+ ## Azure CLI Script to Enable Autoscale IOPS
85+
86+ > [ !NOTE]
87+ > The script below will execute: <br />
88+ > - Using Python 3.13.3 <br />
89+ > - Checks if Azure CLI is available at the specified path. <br />
90+ > - Lists all MySQL Flexible Servers. <br />
91+ > - Tries to get each server’s resource group. <br />
92+ > - If the resource group is missing, it prompts you to enter it. <br />
93+ > - Asks for confirmation before enabling autoscale IOPS. <br />
94+
95+ ``` python
96+ import subprocess
97+ import json
98+
99+ # Step 1: Get list of MySQL Flexible Servers
100+ servers_output = subprocess.check_output(
101+ [" az" , " mysql" , " flexible-server" , " list" , " --query" , " [].name" , " -o" , " tsv" ],
102+ text = True
103+ )
104+ servers = servers_output.strip().splitlines()
105+
106+ # Step 2: Loop through each server and enable autoscale IOPS
107+ for server in servers:
108+ # Get the resource group for the server
109+ rg_output = subprocess.check_output(
110+ [" az" , " mysql" , " flexible-server" , " show" , " --name" , server, " --query" , " resourceGroup" , " -o" , " tsv" ],
111+ text = True
112+ )
113+ resource_group = rg_output.strip()
114+
115+ print (f " Enabling autoscale IOPS for { server} in { resource_group} ... " )
116+
117+ # Update the server to enable autoscale IOPS
118+ subprocess.run([
119+ " az" , " mysql" , " flexible-server" , " update" ,
120+ " --name" , server,
121+ " --resource-group" , resource_group,
122+ " --iops" , " Auto"
123+ ])
124+ ```
125+
126+ ## How to execute it Azure CLI Script to Enable Autoscale IOPS
127+
128+ 1 . Download [ the script] ( ./enable_autoscale_iops.py ) to your local machine or a cloud shell environment.
129+ 2 . Make sure you're logged in: ` az login `
130+ 4 . Run the script: ` py enable_autoscale_iops.py `
131+
132+ > Example: enabling Autoscale IOPS on three different servers, each hosted in a separate resource group but under the same subscription.
133+
134+ <img width =" 550 " alt =" image " src =" https://github.com/user-attachments/assets/22aa763d-b358-441a-b5b9-aa0197ce680d " />
83135
84136
85137
0 commit comments