Home Microsoft AzureSet Up Azure Database for MySQL Flexible Server Step by Step

Set Up Azure Database for MySQL Flexible Server Step by Step

by Knowledge Base Linux
Set Up Azure Database for MySQL — Set Up Azure Database for MySQL Flexible Server Step by Step

Running MySQL on a virtual machine means you own the patching, the backups, the failover and the 3 a.m. disk-full alerts. Azure Database for MySQL Flexible Server removes that operational burden: Microsoft manages the engine, high availability and automated backups while you keep full MySQL compatibility. This guide creates a Flexible Server with the Azure CLI, secures it, and connects from Linux. This article covers Set Up Azure Database for MySQL in detail.

Why Choose Azure Database for MySQL Flexible Server? – Set Up Azure Database for MySQL

Flexible Server is the current-generation deployment option. It supports MySQL 8.0 and 5.7, burstable compute for small workloads, zone-redundant high availability for critical ones, automated backups with point-in-time restore up to 35 days, and the ability to stop the server when unused so you only pay for storage. For most WordPress, WooCommerce and custom PHP applications it is the right default.

Prerequisites – Set Up Azure Database for MySQL

  • An Azure subscription and Azure CLI signed in
  • A resource group, for example rg-linux-prod
  • The MySQL client installed locally (sudo apt install mysql-client on Ubuntu)

Step 1: Create the Azure Database for MySQL Server

az mysql flexible-server create \
  --resource-group rg-linux-prod \
  --name kb-mysql-flex-01 \
  --location eastus \
  --admin-user kbadmin \
  --admin-password 'Str0ng!Passw0rd' \
  --sku-name Standard_B1ms \
  --tier Burstable \
  --version 8.0.21 \
  --storage-size 32 \
  --public-access 203.0.113.10

The --public-access flag creates a firewall rule for your current IP so you can connect immediately; pass None if the server should only be reachable inside a virtual network. In real projects, never hard-code the admin password in shell history — use an environment variable or Azure Key Vault reference.

Connecting securely over SSL to Azure Database for MySQL Flexible Server

Step 2: Add Firewall Rules for Other Clients

az mysql flexible-server firewall-rule create \
  --resource-group rg-linux-prod \
  --name kb-mysql-flex-01 \
  --rule-name AllowAppServer \
  --start-ip-address 203.0.113.20 \
  --end-ip-address 203.0.113.20

Each application server gets its own rule. Avoid the tempting 0.0.0.0–255.255.255.255 range; it exposes your database login page to the entire internet.

Step 3: Create a Database and Application User

az mysql flexible-server db create \
  --resource-group rg-linux-prod \
  --server-name kb-mysql-flex-01 \
  --database-name wordpress

mysql -h kb-mysql-flex-01.mysql.database.azure.com \
  -u kbadmin -p \
  -e "CREATE USER 'wpuser'@'%' IDENTIFIED BY 'An0ther!Strong'; \
      GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'%'; \
      FLUSH PRIVILEGES;"

Your applications should always connect as a least-privilege user like wpuser, never as the server admin.

Step 4: Connect Securely with SSL

Azure Database for MySQL enforces encrypted connections by default (require_secure_transport is ON). Verify and connect with TLS explicitly:

mysql -h kb-mysql-flex-01.mysql.database.azure.com \
  -u wpuser -p \
  --ssl-mode=REQUIRED \
  -e "SHOW DATABASES; STATUS;"

When migrating an existing site, our guide on importing and exporting MySQL databases covers the mysqldump side of the move; the dump loads into Flexible Server with the same client commands shown here. For deeper service details, the Microsoft Learn overview of Azure Database for MySQL Flexible Server explains pricing tiers, networking options and HA modes.

Tuning, Backups and Maintenance Windows

Flexible Server exposes hundreds of server parameters, but only a handful matter early on. Raise max_connections carefully — each connection consumes memory, and burstable tiers run out of RAM before they run out of connection slots; a connection pooler in your application is usually the better fix. Turn on the slow query log (slow_query_log = ON, long_query_time = 2) for the first weeks after a migration to catch unindexed queries inherited from the old server. Automated backups run daily with a 7-day default retention, extendable to 35 days, and on-demand backups can be taken before schema changes. Choose a maintenance window in your quietest hour: Microsoft applies engine patches and security updates inside it, briefly failing over the server. For read-heavy workloads, read replicas in the same or another region can absorb reporting traffic, and zone-redundant high availability on the General Purpose tier protects against a full datacenter failure — enable it at creation time, because it cannot be switched on as cheaply afterwards.

Point-in-Time Restore: Your Undo Button

The feature that sells most teams on managed MySQL is point-in-time restore. Because Flexible Server continuously backs up transaction logs, you can restore the server to any second within the retention window — for example, to 14:03, one minute before a bad migration ran at 14:04. The restore creates a new server rather than overwriting the old one, so you can inspect the recovered data, export what you need with mysqldump, and only then decide whether to switch applications over. Practice this once in a test resource group; the middle of a real incident is the wrong time to learn which Azure region your backups live in or discover that your application connection string hard-codes the old hostname.

Troubleshooting

  • Client is not allowed to connect / IP not whitelisted: your public IP changed. Update the firewall rule with your current address.
  • SSL connection error: the client is negotiating an old TLS version. Flexible Server requires TLS 1.2 or later.
  • Access denied for user: on Flexible Server, admin connections use just the username — do not append the old Single Server style @servername suffix.
  • Slow queries after migration: check server parameters such as slow_query_log and review the Query Performance Insight blade in the portal.

Conclusion

Azure Database for MySQL Flexible Server gives you a managed, backed-up, SSL-enforced MySQL in about ten minutes of CLI work. Combine it with least-privilege users and tight firewall rules, and your database layer stops being the thing that wakes you up at night.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.