Ante Miličević
December 9, 2023

Setup HA Azure Database for MySQL flexible server across multiple regions within Azure private network (P2S)

An easy-to-follow guide for setting up high availability for your Azure MySQL Flexible Server across multiple Azure regions within a private network. Ensure your database remains robust and accessible with these essential steps.

Introduction

In this tutorial, we will guide you through the process of setting up a highly available Azure Database for MySQL across multiple regions within an Azure private network (VNet). We will use a Point-to-Site (P2S) connection to access the private network. Before proceeding with this tutorial, ensure that you have already set up a P2S VPN by following the tutorial available here. Additionally, you will need to have an HA Virtual Network Gateway.

This tutorial consists of the following parts:

  1. Setting up a highly available Azure Database for MySQL across multiple regions.
  2. Implementing disaster recovery measures.

Setting Up Highly Available Azure Database for MySQL across Multiple Regions

Follow the steps below to set up a highly available Azure Database for MySQL across multiple regions:
<ol>
 <li>Deploy the primary Azure Database for MySQL instance with the desired configuration, ensuring that private access is enabled.
   <img src="https://assets-global.website-files.com/64d4f32bbf4bcd247875f1b1/6539effdeaca94e44a93b4ca_HA-Azure-Database-for-MySQL-1.png" alt="HA-Azure-Database-for-MySQL-1">
 </li>
 <li>Set up a P2S connection for the VNet where the primary Azure Database for MySQL is deployed.</li>
 <li>Deploy a VNet in a different region to host the secondary database and set up an HA VPN network gateway. You can find a tutorial on setting up an HA VPN network gateway here.</li>
 <li> Configure the secondary database as a read replica:
   <ol type="i">
     <li>Navigate to the primary database instance you deployed.</li>
     <li>Click on "Replication."</li>
     <li>Click on "Add replica."<img src="https://assets-global.website-files.com/64d4f32bbf4bcd247875f1b1/6539f000bf1c01e08d7b631d_HA-Azure-Database-for-MySQL-2.png" alt="HA-Azure-Database-for-MySQL-2"></li>
   </ol>
 </li>
</ol>    

Implementing Disaster Recovery Measures

As Azure Database for MySQL does not support automatic failover, you need to follow the steps below to handle disaster recovery:
<ol>
 <li> Promote the replica Azure Database for MySQL to become the primary instance:
   <ol type="i">
     <li>Go to your primary Azure Database for MySQL instance.</li>
     <li>Click on "Replication."</li>
     <li>Locate the replica database and click on "Promote."<img src="https://assets-global.website-files.com/64d4f32bbf4bcd247875f1b1/6539effe47bf89d9cb96f9eb_HA-Azure-Database-for-MySQL-3.png" alt="HA-Azure-Database-for-MySQL-3"
</li>
   </ol>
 </li>
 <li>Update the connection string in your applications:
   Updating the connection string manually in multiple applications can be painful. However, there is a workaround using a private DNS zone. Follow these steps to simplify the process:
   Create a CNAME record in your Azure private DNS zone, such as "prod," pointing to the primary Azure Database for MySQL instance.
   <img src="https://assets-global.website-files.com/64d4f32bbf4bcd247875f1b1/6539effdb01b8c534a32c14c_HA-Azure-Database-for-MySQL-4.png" alt="HA-Azure-Database-for-MySQL-4">
   In the event of a disaster, you can edit the "prod" CNAME record to point to the promoted replica database, which will become the new primary instance. That being said, you avoided the changing connection string in your application, since it will remain the same, in this case “prod….”.
 </li>
</ol>    

Conclusion

While not all Azure resources require manual intervention in the event of a region failure, Azure Database for MySQL flexible server has certain limitations. To ensure high availability, you must promote a replica database and update the CNAME record to point to the new primary instance. By following the steps outlined in this tutorial, you can effectively set up HA Azure Database for MySQL across multiple regions within an Azure private network.

Facing Challenges in Cloud, DevOps, or Security?
Let’s tackle them together!

get free consultation sessions

In case you prefer e-mail first:

Thank you! Your message has been received!
We will contact you shortly.
Oops! Something went wrong while submitting the form.
By clicking “Accept”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information. If you wish to disable storing cookies, click here.