Developers can now accelerate development time and focus only on the core business logic of their applications, for developing event-driven applications with Azure Database for MySQL as the backend data store.
We are excited to announce that you can now invoke an Azure Function based on changes to an Azure Database for MySQL table. This new capability is made possible through the Azure Database for MySQL triggers for Azure Functions, now available in public preview.
Azure Database for MySQL triggers
The Azure Database for MySQL trigger uses change tracking functionality to monitor a MySQL table for changes and trigger a function when a row is created, updated, or deleted enabling customers to build highly-scalable event-driven applications.
Similar to the Azure Database for MySQL Input and Output bindings for Azure Functions, a connection string for the MySQL database is stored in the application settings of the Azure Function to trigger the function when a change is detected on the tables.
Note: In public preview, Azure Database for MySQL triggers for Azure Functions are available only for dedicated and premium plan of Azure Functions
To enable change tracking on an existing Azure Database for MySQL table to use trigger bindings for an Azure Function, it is necessary to alter the table structure, for example, enabling change tracking on an employees data table:
ALTER TABLE employees
ADD COLUMN az_func_updated_at TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP;
Azure Database for MySQL trigger uses the 'az_func_updated_at' and column's data to monitor the table for any changes on which change tracking is enabled.
Changes are then processed in the order that they were made, with the oldest changes being processed first.
Important:
- If changes to multiple rows are made at once, then the exact order they're sent to the function is determined on the ascending order of the az_func_updated_at and the primary key columns.
- If multiple changes are made to a row in-between an iteration, then only the latest changes for that particular rows are considered.
The following example demonstrates a C# function that is triggered when changes occur in the employees table. The MySQL trigger uses attributes for the table name and the connection string.
using System.Collections.Generic;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.MySql;
using Microsoft.Extensions.Logging;
namespace EmployeeSample.Function
{
public static class EmployeesTrigger
{
[FunctionName(nameof(EmployeesTrigger))]
public static void Run(
[MySqlTrigger("Employees", "MySqlConnectionString")]
IReadOnlyList<MySqlChange<Employee>> changes,
ILogger logger)
{
foreach (MySqlChange<Employee> change in changes)
{
Employee employee= change. Item;
logger.LogInformation($"Change operation: {change.Operation}");
logger.LogInformation($"EmployeeId: {employee.employeeId}, FirstName: {employee.FirstName}, LastName: {employee.LastName}, Company: {employee. Company}, Department: {employee. Department}, Role: {employee. Role}");
}
}
}
}
Join the preview and share your feedback!
We are eager for you to try out the new Azure Database for MySQL triggers for Azure Functions and build highly scalable event-driven and serverless applications.
For more information refer https://aka.ms/mysqltriggers about using MySQL triggers for all the supported programming frameworks with detailed step-by-step instructions
If you have any feedback or questions about the information provided above, please leave a comment below or email us at AskAzureDBforMySQL@service.microsoft.com. Thank you!
Updated Mar 10, 2025
Version 2.0Sai_Kondapalli
Microsoft
Joined July 01, 2021
Azure Database for MySQL Blog
Follow this blog board to get notified when there's new activity