This post was brought to you by Kumar Allamraju.

Azure Database for MySQL

Azure Database for MySQL provides fully managed, enterprise-ready community MySQL database as a service. The MySQL Community edition helps you easily lift and shift your on-prem MySQL Database to the Azure Cloud, using languages and frameworks of your choice. On top of that, you get built-in high availability and dynamic scaling, helping you easily adjust to changes in customer demands.

In few simple steps we will learn to create Azure managed MySQL database using az CLI

Learn how to setup Azure Database for MySQL using

  • Azure CLI
  • Azure Portal

Azure CLI

- az login
- az account set --subscription <subscription-id>
- az extension add --name db-up
- az mysql up
1
2
3
4

The above az CLI commands will create a MySQL Database with system defaults, firewall rule, an empty database "sampledb". Refer to the screenshot below

az account set --subscription xxxx-xxxx-xxxx-xxxx
az extension add --name db-up
az mysql up

Creating Resource Group 'group1799424947'...
Creating MySQL Server 'server623497231' in group 'group1799424947'...
Configuring wait timeout to 8 hours...
Configuring server firewall rule, 'azure-access', to accept connections from all Azure resources...
Creating MySQL database 'sampledb'...
Checking your ip address...
Configuring server firewall rule, 'devbox', to allow for your ip address: 167.220.26.66
If MySQL server declines your IP address, please create a new firewall rule using:
    `az mysql server firewall-rule create -g group1799424947 -s server623497231 -n {rule_name} --start-ip-address {ip_address} --end-ip-address {ip_address}`
Successfully Connected to MySQL.
Ran Database Query: `CREATE USER 'root' IDENTIFIED BY 'Sampledb1'`
Ran Database Query: `GRANT ALL PRIVILEGES ON sampledb.* TO 'root'`
{
  "connectionStrings": {
    "ado.net": "Server=server623497231.mysql.database.azure.com; Port=3306; Database=sampledb; Uid=eatableKitten3@server623497231; Pwd=f70ea0e1-b0ae-4819-aec3-02017460c70f;",
    "jdbc": "jdbc:mysql://server623497231.mysql.database.azure.com:3306/sampledb?user=eatableKitten3@server623497231&password=f70ea0e1-b0ae-4819-aec3-02017460c70f",
    "jdbc Spring": "spring.datasource.url=jdbc:mysql://server623497231.mysql.database.azure.com:3306/sampledb  spring.datasource.username=eatableKitten3@server623497231  spring.datasource.password=f70ea0e1-b0ae-4819-aec3-02017460c70f",
    "mysql_cmd": "mysql sampledb --host server623497231.mysql.database.azure.com --user eatableKitten3@server623497231 --password=f70ea0e1-b0ae-4819-aec3-02017460c70f",
    "node.js": "var conn = mysql.createConnection({host: 'server623497231.mysql.database.azure.com', user: 'eatableKitten3@server623497231', password: f70ea0e1-b0ae-4819-aec3-02017460c70f, database: sampledb, port: 3306});",
    "php": "host=server623497231.mysql.database.azure.com port=5432 dbname=sampledb user=eatableKitten3@server623497231 password=f70ea0e1-b0ae-4819-aec3-02017460c70f",
    "python": "cnx = mysql.connector.connect(user='eatableKitten3@server623497231', password='f70ea0e1-b0ae-4819-aec3-02017460c70f', host='server623497231.mysql.database.azure.com', port=3306, database='sampledb')",
    "ruby": "client = Mysql2::Client.new(username: 'eatableKitten3@server623497231', password: 'f70ea0e1-b0ae-4819-aec3-02017460c70f', database: 'sampledb', host: 'server623497231.mysql.database.azure.com', port: 3306)",
    "webapp": "Database=sampledb; Data Source=server623497231.mysql.database.azure.com; User Id=eatableKitten3@server623497231; Password=f70ea0e1-b0ae-4819-aec3-02017460c70f"
  },
  "host": "server623497231.mysql.database.azure.com",
  "password": "f70ea0e1-b0ae-4819-aec3-02017460c70f",
  "username": "eatableKitten3@server623497231"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

Pls go to the Azure Portal and check the provisioned Azure MySQL database. Refer to the screenshot below

You can install the MySQL workbench in your desktop and connect to the provisioned MySQL database in Azure Cloud. Use the connection string shown in the above screenshot i.e. server623497231.mysql.database.azure.com

Once you are done playing with the MySQL database, pls delete the database to clean up the resources in your subscription.

az mysql down --delete-group 
Are you sure you want to perform this operation? (y/n): y
Deleting Resource Group 'group1799424947'...
1
2
3

If you want to create Azure MySQL database with detailed steps pls refer to MySQL-Azure CLI

Azure Portal

To setup MySQL database from Azure portal, pls follow this workflow [MySQL].

Conclusion

Azure Database for MySQL is a relational database service based on the open-source MySQL Server engine. It's a fully managed database as a service offering that can handle mission-critical workloads with predictable performance and dynamic scalability. In this article, we only scratched the surface of Azure managed databases. You can further explore the advanced features of Azure managed databases like Scale In/Out, High Availability, Data-in replication, Read replicas, Advanced Threat Protection, VNet integration etc.. You can follow similar steps to configure PostgreSQL and MariaDB databases as well.