AzureTipsAndTricks/blog/tip326.md

96 строки
6.6 KiB
Markdown

---
type: post
title: "Tip 326 - How to use Flexible Server in Azure Database for MySQL"
excerpt: "Learn how to use Flexible Server in Azure Database for MySQL"
tags: [Databases]
share: true
date: 2021-07-28 12:00:00
---
::: tip
:fire: Checkout the Azure Developer page at [azure.com/developer](https://azure.com/developer?WT.mc_id=azure-azuredevtips-azureappsdev).
:bulb: Learn more : [about Azure Database for MySQL](https://docs.microsoft.com/azure/mysql/overview?WT.mc_id=docs-azuredevtips-azureappsdev).
:tv: Watch the video : [How to use Flexible Server in Azure Database for MySQL](https://youtu.be/2YasHdel_VY?WT.mc_id=youtube-azuredevtips-azureappsdev).
:::
### How to use Flexible Server in Azure Database for MySQL
#### Highly configurable MySQL server
[Azure Database for MySQL](https://docs.microsoft.com/azure/mysql/overview?WT.mc_id=docs-azuredevtips-azureappsdev) 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](https://docs.microsoft.com/azure/mysql/single-server-overview?WT.mc_id=docs-azuredevtips-azureappsdev), 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](https://docs.microsoft.com/azure/mysql/flexible-server/overview?WT.mc_id=docs-azuredevtips-azureappsdev), 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.
#### Prerequisites
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](https://azure.microsoft.com/free/?WT.mc_id=azure-azuredevtips-azureappsdev) 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](https://docs.microsoft.com/azure/cloud-shell/overview?WT.mc_id=docs-azuredevtips-azureappsdev).
1. Go to the [Azure portal](https://portal.azure.com/?WT.mc_id=azure-azuredevtips-azureappsdev)
2. Click the **Create a resource** button (the plus-sign in the top left corner)
3. Search for **database for mysql**, select the "Azure Database for MySQL" result and click **Create**
1. This shows the Select **Azure Database for MySQL deployment option** screen
<img :src="$withBase('/files/115start.png')">
(Azure Database for MySQL server options)
2. Click the **Create** button under **Flexible server**. This opens the Flexible server blade
3. Select a **Resource Group**
4. Fill in a **Name** for the server
5. Select a **Region**
6. 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
<img :src="$withBase('/files/115create1.png')">
(Flexible server creation options)
7. 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)
<img :src="$withBase('/files/115create2.png')">
(Compute + storage options)
8. Next, choose the **availability zone** you want the VM(s) that runs the MySQL server to use
9. 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
10. Leave the **MySQL version** to the selected version
11. Fill in an **Admin username** that you will use to connect to the server
12. Type a **Password** for the admin user and **confirm the password**
13. Select **Next:Networking**
<img :src="$withBase('/files/115create3.png')">
(Configure networking options)
14. 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)**
15. 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
16. 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.
<img :src="$withBase('/files/115stop.png')">
(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.
1. Go to [https://shell.azure.com/](https://shell.azure.com/?WT.mc_id=azure-azuredevtips-azureappsdev)
2. 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.
<img :src="$withBase('/files/115result.png')">
(Connected to the flexible server from the Azure Cloud Shell)
#### Conclusion
The [Flexible server](https://docs.microsoft.com/azure/mysql/flexible-server/overview?WT.mc_id=docs-azuredevtips-azureappsdev) option for [Azure Database for MySQL](https://docs.microsoft.com/azure/mysql/overview?WT.mc_id=docs-azuredevtips-azureappsdev) allows you to customize high availability, maintenance windows, use burstable compute, and stop and start the server. Go and check it out!