🔥 Checkout the Azure Developer page at azure.com/developer (opens new window).
💡 Learn more : about Azure Database for MySQL (opens new window).
📺 Watch the video : How to use Flexible Server in Azure Database for MySQL (opens new window).
# How to use Flexible Server in Azure Database for MySQL
# Highly configurable MySQL server
Azure Database for MySQL (opens new window) provides a managed MySQL server that allows you to focus on using MySQL, instead of focussing on managing your database server. You can choose to run Azure Database for MySQL as a Single server (opens new window), which is designed to handle most of the database management functions such as patching, backups, high availability, and security with minimal user configuration and control. You can also create an Azure Database for MySQL with a Flexible Server (opens new window), which allows for more configuration and control of the database server.
In this post, we'll create an Azure Database for MySQL with the Flexible Server option.
If you want to follow along, you'll need the following:
- An Azure subscription (If you don't have an Azure subscription, create a free account (opens new window) before you begin)
# Create a Flexible MySQL server
We will use the Azure portal to create an Azure Database for MySQL and connect to it using the Azure Cloud Shell (opens new window).
Go to the Azure portal (opens new window)
Click the Create a resource button (the plus-sign in the top left corner)
Search for database for mysql, select the "Azure Database for MySQL" result and click Create
- This shows the Select Azure Database for MySQL deployment option screen
(Azure Database for MySQL server options)
- Click the Create button under Flexible server. This opens the Flexible server blade
- Select a Resource Group
- Fill in a Name for the server
- Select a Region
- Choose a Workload type. This determines the compute and storage option that you use. Flexible server offers the option to use Burstable compute, which ramps up the server CPU only when needed. This is great for non-production workloads
(Flexible server creation options)
- You can configure compute and storage in more detail, by clicking on configure server. This brings up the Compute + storage blade. This allows you to set the size of the VM that the server runs on, and the storage size and performance that your data sits on. In this blade, you can also configure the server backups and make them geo-redundant (you can only choose this when you don't use a burstable compute tier)
(Compute + storage options)
- Next, choose the availability zone you want the VM(s) that runs the MySQL server to use
- Leave the High Availability setting unchecked. You should use this when you want additional availability precautions within availability zones, for production workloads. As we are using the burstable compute tier for development workloads, we don't need this
- Leave the MySQL version to the selected version
- Fill in an Admin username that you will use to connect to the server
- Type a Password for the admin user and confirm the password
- Select Next:Networking
(Configure networking options)
- Flexible server can put the server in a virtual network, so that it is not exposed to the internet. You can also allow the server to be accessed through the internet and secure it with a firewall. This is what we will do. Select Public access (allowed IP addresses)
- Under Firewall rules, select the Add 0.0.0.0 - 255.255.255.255 link to add a firewall rule that allows all IP addresses to access the server. You should never use this firewall rule for a real-world application, but you can use it for development or demo purposes
- Click Review + create and Create after that to create the server
When the Azure Database for MySQL server is created, navigate to it in the Azure portal. In the overview blade, you'll see that you can stop the server. This is a feature of Flexible server. Stopping the server can save you a lot of money when you don't use it.
(Stop the server from the Azure portal)
You can use the Azure Database for MySQL server with your tool of choice. We will use the Azure Cloud Shell to connect to it. Azure Cloud Shell comes with the mysql.exe tool preinstalled, through which we can use the MySQL server.
- Go to https://shell.azure.com/ (opens new window)
- Execute the following commands, and replace the servername and username with your own. Note that these commands will first get a certificate that is needed to secure the connection to the server, and use that certificate in the connection command.
mysql -h servername.mysql.database.azure.com -u username -p --ssl=true
That's it. We are now connected to the Azure Database for MySQL flexible server.
(Connected to the flexible server from the Azure Cloud Shell)
The Flexible server (opens new window) option for Azure Database for MySQL (opens new window) allows you to customize high availability, maintenance windows, use burstable compute, and stop and start the server. Go and check it out!