Connect Azure Database for MySQL - Flexible Server with private access connectivity method
APPLIES TO: Azure Database for MySQL - Flexible Server
Azure Database for MySQL Flexible Server is a managed service that runs, manages, and scales highly available MySQL servers in the cloud. This quickstart shows you how to create an Azure Database for MySQL Flexible Server instance in a virtual network by using the Azure portal.
If you don't have an Azure subscription, create an Azure trial account before you begin.
Sign in to the Azure portal
Sign in to the Azure portal. Enter your credentials to sign in to the portal. The default view is your service dashboard.
Create an Azure Database for MySQL Flexible Server instance
You create an Azure Database for MySQL Flexible Server instance with a defined set of compute and storage resources. You create the server within an Azure resource group.
Complete these steps to create an Azure Database for MySQL Flexible Server instance:
Search for and select Azure Database for MySQL servers in the portal:
Select Add.
On the Select Azure Database for MySQL deployment option page, select Flexible server as the deployment option:
On the Basics tab, enter the subscription, resource group , region, administrator username and administrator password. With the default values, this provisions an Azure Database for MySQL Flexible Server instance of version 5.7 with Burstable Sku using 1 vCore, 2 GiB Memory, and 32 GiB storage. The backup retention is seven days. You can change the configuration.
Tip
For faster data loads during migration, increasing the IOPS to the maximum size supported by computing the size and later scaling it back to save cost is recommended.
Go to the Networking tab, select private access.You can't change the connectivity method after you create the server. Select Create virtual network to create a new virtual network vnetenvironment1.
Select OK once you've provided the virtual network name and subnet information.
Select Review + create to review your Azure Database for MySQL Flexible Server configuration.
Select Create to provision the server. Provisioning can take a few minutes.
Wait until the deployment is complete and successful.
Select Go to resource to view the server's Overview page opens.
Create Azure Linux virtual machine
Since the server is in a virtual network, you can only connect to the server from other Azure services in the same virtual network as the server. To connect and manage the server, let's create a Linux virtual machine. The virtual machine must be created in the same region and same subscription. The Linux virtual machine can be used as SSH tunnel to manage your database server.
Go to your resource group in which the server was created. Select Add.
Select Ubuntu Server 18.04 LTS
In the Basics tab, under Project details, make sure the correct subscription is selected and then choose to Create new resource group. Type myResourceGroup for the name.
Under Instance details, type myVM for the Virtual machine name, choose the same Region as your database server.
Under Administrator account, select SSH public key.
In Username type azureuser.
For SSH public key source, leave the default of Generate new key pair, and then type myKey for the Key pair name.
Under Inbound port rules > Public inbound ports, choose Allow selected ports and then select SSH (22) and HTTP (80) from the dropdown.
Select Networking page to configure the virtual network. For the virtual network, choose the vnetenvironment1 created for the Azure Database for MySQL Flexible Server instance.
Select Manage subnet configuration to create a new subnet for the server.
Add a new subnet for the virtual machine.
After the subnet has been created successfully, close the page.
Select Review + Create.
Select Create. When the Generate new key pair window opens, select Download private key and create resource. Your key file is downloaded as myKey.pem.
Important
Make sure you know where the
.pem
file was downloaded, you need the path to it in the next step.When the deployment is finished, select Go to resource.
On the page for your new VM, select the public IP address and copy it to your clipboard.
Install MySQL client tools
Create an SSH connection with the VM using Bash or PowerShell. At your prompt, open an SSH connection to your virtual machine. Replace the IP address with the one from your VM, and replace the path to the .pem
with the path to where the key file was downloaded.
ssh -i .\Downloads\myKey1.pem azureuser@10.111.12.123
Tip
The SSH key you created can be used the next time you create a VM in Azure. Select the Use a key stored in Azure for SSH public key source the next time you create a VM. You already have the private key on your computer, so you won't need to download anything.
You need to install mysql-client tool to connect to the server.
sudo apt-get update
sudo apt-get install mysql-client
Connections to the database are enforced with SSL; hence you need to download the public SSL certificate.
wget --no-check-certificate https://dl.cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem
Connect to the server from Azure Linux virtual machine
With the mysql.exe client tool installed, we can now connect to the server from your local environment.
mysql -h mydemoserver.mysql.database.chinacloudapi.cn -u mydemouser -p --ssl-mode=REQUIRED --ssl-ca=DigiCertGlobalRootCA.crt.pem
Clean up resources
You've created an Azure Database for MySQL Flexible Server instance in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group or the Azure Database for MySQL Flexible Server instance. To delete the resource group, complete these steps:
- Search for and select Resource groupsin the Azure portal.
- In the list of resource groups, select the name of your resource group.
- In the Overview page for your resource group, select Delete resource group.
- In the confirmation dialog box, type the name of your resource group and then select Delete.