MS

Azure Database for MySQL – Performance

Overview

Azure Database for MySQL delivers a fully managed, enterprise‑grade MySQL database service with built-in high availability, security, and scaling. Optimizing performance is critical for delivering low‑latency applications.

Monitoring & metrics

Use Azure Monitor, Query Performance Insight, and MySQL's performance_schema to gather actionable metrics.

Key metrics

MetricDescription
CPU usageCPU utilization of the server tier.
Memory usageRAM consumption vs. allocated memory.
IOPSRead/write operations per second.
Slow queriesQueries exceeding the threshold (default 1 s).

Query performance

Identify slow queries and refine them using EXPLAIN and optimizer hints.

EXPLAIN ANALYZE
SELECT
    o.id,
    c.name,
    SUM(oi.quantity * oi.unit_price) AS total
FROM orders o
JOIN customers c ON o.customer_id = c.id
JOIN order_items oi ON o.id = oi.order_id
WHERE o.order_date >= '2024-01-01'
GROUP BY o.id, c.name
ORDER BY total DESC
LIMIT 10;

Enable the slow_query_log to capture long‑running queries:

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 1;

Indexing strategies

Use appropriate indexes to accelerate lookups. Consider covering indexes for frequently accessed columns.

CREATE INDEX idx_orders_customer_date
ON orders (customer_id, order_date);

Remove unused indexes to reduce write overhead:

DROP INDEX idx_orders_old ON orders;

Scaling & resources

Azure Database for MySQL offers vertical scaling (compute tier) and horizontal read replicas.

Vertical scaling

  • Upgrade the compute size (e.g., from General Purpose B2s to B4ms).
  • Increase storage IOPS and size to meet throughput demands.

Read replicas

Configure a read replica for offloading read‑heavy workloads.

az mysql server replica create \\
  --resource-group MyResourceGroup \\
  --name myreadreplica \\
  --source-server myprimary

Best practices

  1. Enable performance_schema and regularly review events_waits_summary_by_host_by_event_name.
  2. Keep your MySQL version up‑to‑date to benefit from optimizer improvements.
  3. Use connection pooling to reduce overhead.
  4. Monitor and adjust innodb_buffer_pool_size to ~70‑80% of memory.
  5. Implement proper backup retention and point‑in‑time restore.