Configure and access slow query logs from the Azure portal
APPLIES TO: Azure Database for MySQL - Single Server
Important
Azure Database for MySQL single server is on the retirement path. We strongly recommend that you upgrade to Azure Database for MySQL flexible server. For more information about migrating to Azure Database for MySQL flexible server, see What's happening to Azure Database for MySQL Single Server?
You can configure, list, and download the Azure Database for MySQL slow query logs from the Azure portal.
Prerequisites
The steps in this article require that you have Azure Database for MySQL server.
Configure logging
Configure access to the MySQL slow query log.
Sign in to the Azure portal.
Select your Azure Database for MySQL server.
Under the Monitoring section in the sidebar, select Server logs.
To see the server parameters, select Click here to enable logs and configure log parameters.
Turn slow_query_log to ON.
Select where to output the logs to using log_output. To send logs to both local storage and Azure Monitor Diagnostic Logs, select File.
Consider setting "long_query_time" which represents query time threshold for the queries that will be collected in the slow query log file, The minimum and default values of long_query_time are 0 and 10, respectively.
Adjust other parameters, such as log_slow_admin_statements to log administrative statements. By default, administrative statements are not logged, nor are queries that do not use indexes for lookups.
Select Save.
From the Server Parameters page, you can return to the list of logs by closing the page.
View list and download logs
After logging begins, you can view a list of available slow query logs, and download individual log files.
Open the Azure portal.
Select your Azure Database for MySQL server.
Under the Monitoring section in the sidebar, select Server logs. The page shows a list of your log files.
Tip
The naming convention of the log is mysql-slow-< your server name>-yyyymmddhh.log. The date and time used in the file name is the time when the log was issued. Log files are rotated every 24 hours or 7.5 GB, whichever comes first.
If needed, use the search box to quickly narrow down to a specific log, based on date and time. The search is on the name of the log.
To download individual log files, select the down-arrow icon next to each log file in the table row.
Set up diagnostic logs
Under the Monitoring section in the sidebar, select Diagnostic settings > Add diagnostic settings.
Provide a diagnostic setting name.
Specify which data sinks to send the slow query logs (storage account, event hub, or Log Analytics workspace).
Select MySqlSlowLogs as the log type.
After you've configured the data sinks to pipe the slow query logs to, select Save.
Access the slow query logs by exploring them in the data sinks you configured. It can take up to 10 minutes for the logs to appear.
Next steps
- See Access slow query Logs in CLI to learn how to download slow query logs programmatically.
- Learn more about slow query logs in Azure Database for MySQL.
- For more information about the parameter definitions and MySQL logging, see the MySQL documentation on logs.