How to reduce cost of azure database for mysql , created for wordpress

Muhammad Qasim 41 Reputation points

I have created a resource for hosting my wordpress website on azure. From marketplace i searched for wordpress and on first option wordpress was present in that search and i selected that option and created resource for wordpress. Now i am creating my wordpress website on azure and haven't published it yet bc it is underdevelopment. Now when I want to edit and work on my wordpress website then i login on azure and start the resource for that wordpress website and start editing my wordpress website online. and when i decide to stop editing my website then i also stop that resource to minime my cost. I also selected free tier :F1 app service plan.
Now when i logged in to azure then from 150 usd credits were decreased to 108 after two days but i had stop the resource but still charged. When i checked the details of costs then founded 35$ used by "azure database for mysql" . Now i changed the pricing tier of database for mysql but now i want to ask that is there any way to stop this service when i am not using it.
Can i stop this service Azure Database for MySQL server when i am not using it?
actually this service is costing about 35$ just for few days and i want to stop it when i am not using it.

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
709 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Hendrik Kruger 5 Reputation points

    You can automate the MySQL server stop / start by using below script and setting up schedules.

    Set up Automation Account (

    Configure managed Identity (

    Add MySQL_Stop_Start Runbook (

    Set up Runbook schedules (

    • You'll have to specify the parameters for START and STOP schedules

    User's image

    User's image

    Paste below script in your powershelgl runbook

    Add your TenantID, SubscriptionID and ClientID details

    #Envrionment parameters
    [string] $resourceGroupName, 
    [string] $MySqlInstanceName, 
    [string] $action
    filter timestamp {"[$(Get-Date -Format G)]: $_"} 
    Write-Output "Azure Automation Script started." | timestamp 
    #$VerbosePreference = "Continue" ##enable this for verbose logging
    $ErrorActionPreference = "Stop" 
    # Ensures you do not inherit an AzContext in your runbook
    Disable-AzContextAutosave -Scope Process
    Write-Output "Detecting environment"
            Write-Output "Azure detected. Authenticating via Managed Identity"
            # Attempt Azure System Managed Identity Authentication
            $AzureContext = (Connect-AzAccount -Identity -Subscription $subscriptionID -ErrorAction Stop).context
            # Set and store context
            $AzureContext = Set-AzContext -Subscription $subscriptionID
            Write-Output "Successfully connected using Azure Managed Identity. Running in Azure Automation"
            Write-Host "Something went wrong. Azure environment detected but authenticating via Managed Identity failed.`
            Alerting owners and existing."
            #TODO: Send Azure Alert for failed authentication
    $startTime = Get-Date 
    Write-Output "Azure Automation local time: $startTime." | timestamp 
    # Get the authentication token 
    $azContext = Get-AzContext
    $azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
    $profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
    $token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
    $authHeader = @{
        'Authorization'='Bearer ' + $token.AccessToken
    Write-Output "Authentication Token acquired." | timestamp 
    ##Invoke REST API Call based on specified action
    if($action -eq 'stop')
            # Invoke the REST API
            $response = Invoke-RestMethod -Uri $restUri -Method POST -Headers $authHeader
            Write-Output "MySQL Single Database Instance $MySqlInstanceName in Resource Group $resourceGroupName is getting stopped." | timestamp 
            # Invoke the REST API
            $response = Invoke-RestMethod -Uri $restUri -Method POST -Headers $authHeader
            Write-Output "MySQL Single Database Instance $MySqlInstanceName in Resource Group $resourceGroupName is getting started." | timestamp 
    Write-Output "MySQL Single Database Instance $MySqlInstanceName in Resource Group $resourceGroupName $action operation completed successfully." | timestamp 
    Write-Output "Azure Automation Script finished." | timestamp
    1 person found this answer helpful.
    0 comments No comments

  2. Anurag Sharma 17,566 Reputation points

    Hi @Anonymous , welcome to Microsoft Q&A forum.

    To reduce the cost of Azure Database for MySQL Server, we can stop the server and then start it when we want to use it again. When the server is in the Stopped state, the server's compute is not billed. However, storage continues to to be billed as the server's storage remains to ensure that data files are available when the server is started again.

    So stopping the server would definitely reduce some cost based on stoppage duration. You can refer to below link for more details:

    Stop/Start an Azure Database for MySQL

    Below article will show how can we stop it using azure portal through a button click or through Azure CLI:

    How to stop/start the Azure Database for MySQL

    Azure Portal:

    Azure CLI commands:

    -- To stop  
    az mysql server stop --name <server-name> -g <resource-group-name>  
    ---- To start  
    az mysql server start --name <server-name> -g <resource-group-name>  

    I would also suggest you to once go through below link that talks about Flexible Server for Azure MySQL and ways to save more costs:

    Save cost with RIs and by stopping the Azure DB for MySQL Flexible Server instance for up to 30 days

    Please let us know if this helps or else we can discuss further. If answer helps, you can mark it 'Accept Answer'.

    0 comments No comments