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
| Metric | Description |
|---|---|
| CPU usage | CPU utilization of the server tier. |
| Memory usage | RAM consumption vs. allocated memory. |
| IOPS | Read/write operations per second. |
| Slow queries | Queries 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
- Enable
performance_schemaand regularly reviewevents_waits_summary_by_host_by_event_name. - Keep your MySQL version up‑to‑date to benefit from optimizer improvements.
- Use connection pooling to reduce overhead.
- Monitor and adjust
innodb_buffer_pool_sizeto ~70‑80% of memory. - Implement proper backup retention and point‑in‑time restore.