Monitoring MySQL with Datadog - Two Data Paths and Permissions

For MySQL running on premises or on EC2, the single check bundled with the Agent can handle both the standard integration and Database Monitoring. This guide starts from the different questions performance_schema and the slow query log answer, then follows the settings fixed at startup, log ingestion, and permissions in that order.

performance_schema and the slow query log answer different questions

There are three kinds of material about MySQL that you can send to Datadog: server-wide statistics, query statistics accumulated in performance_schema, and the slow query log. The standard integration collects throughput, connection counts, errors, and InnoDB metrics, and requires no additional installation on the MySQL server (as of October 2026; source: MySQL). To see per-query metrics, running queries, wait events, and execution plans, enable Database Monitoring (DBM) in the same check; that material is taken from performance_schema. The slow query log is a separate path, where the Agent reads the file as logs.

MySQL information sources and where they land in Datadog (as of October 2026)
Information sourceWhere it lands in DatadogQuestion it answersPreparation on the MySQL side
Server-wide statisticsThe standard MySQL integrationHow are connections and throughput behavingA datadog user with REPLICATION CLIENT / PROCESS privileges
performance_schemaDBM (dbm: true in the configuration)Which queries are heavy and what are they waiting onTurn on performance_schema and the required consumers
Slow query logLog Management (logs in mysql.d)When did a single statement exceed the threshold, and what was itSet slow_query_log and long_query_time
Source: MySQL / Setting Up Database Monitoring for self hosted MySQL

What remains in the slow query log are statements that took longer than long_query_time seconds to execute and examined at least min_examined_row_limit rows (source: The Slow Query Log). If a large number of fast queries that stay under the threshold are creating load, they leave no trace in the log, so you track them on the performance_schema side, which aggregates per query. Conversely, if you want to reread the actual statements that were running at the time of an incident, the log path is useful. Keeping both side by side lets you match the overall picture of load against individual evidence on the same timeline.

performance_schema is fixed at startup, while consumers can be enabled while running

For DBM to collect query metrics, samples, and execution plans, enable performance_schema and specify several options on the command line or in a configuration file such as mysql.conf. In the official MySQL 8.4 manual, performance_schema is enabled by default. To set it explicitly, the manual shows passing the variable at startup, for example by writing performance_schema=ON under [mysqld] in my.cnf (source: Performance Schema Quick Start). In other words, enabling it on a server where it is OFF requires a plan to change the startup configuration and restart MySQL. You can tell whether it is currently enabled by checking whether the value of SHOW VARIABLES LIKE 'performance_schema'; is ON.

Values to set on the MySQL side for DBM (MySQL 5.7 and later, as of October 2026)
ParameterValueStatus
performance_schemaONRequired
max_digest_length4096Required to collect long queries (with the default, queries longer than 1,024 characters are not collected)
performance_schema_max_digest_length / performance_schema_max_sql_text_length4096Match max_digest_length
performance-schema-consumer-events-statements-currentONRequired (running queries)
performance-schema-consumer-events-waits-currentONRequired (wait events)
performance-schema-consumer-events-statements-history-longONRecommended (makes it easier to capture execution details of rare queries)
Source: Setting Up Database Monitoring for self hosted MySQL

Consumers are switches that decide which performance_schema records are kept. Datadog recommends creating a procedure called datadog.enable_events_statements_consumers. With this procedure, the Agent can enable the performance_schema.events_* consumers at runtime. The procedure consists of two statements that update the setup_consumers table, and you grant execute privileges on it to the datadog user. What requires a restart is switching performance_schema itself; consumers can be added later without stopping the server.

RDS and Aurora follow a different procedure; self-managed servers connect from an Agent on the same host

For Amazon RDS and Aurora MySQL, you cannot install the Agent on the database host, so the procedure is different and is covered in the article on monitoring RDS. For MySQL you run yourself on premises or on EC2, the recommended form is to install the Agent on the same server and connect over 127.0.0.1 or a socket. In the configuration, write 127.0.0.1 rather than localhost for host, and specify sock if you use a socket. Not putting a proxy, load balancer, or connection pooler in between, and the reasons for it, are the same as for RDS (as of October 2026; source: Setting Up Database Monitoring for self hosted MySQL).

Minimum Agent and MySQL versions for self-managed MySQL (as of October 2026)
Feature usedMinimum Agent versionMinimum MySQL version
Standard integration6.0.05.6
DBM7.36.15.6
Source: MySQL / Setting Up Database Monitoring for self hosted MySQL

MariaDB has its own separate DBM procedure, so do not apply the same configuration; check that procedure instead. Installing the Agent on the server itself is the same as in installing the Agent on Linux, and the MySQL check is included in the Agent package.

Four steps for the slow query log to reach the Agent

By default, MySQL logs are written to /var/log/syslog, which requires root privileges to read. In the official documentation's procedure, first comment out all lines in /etc/mysql/conf.d/mysqld_safe_syslog.cnf. Next, write slow_query_log = on, slow_query_log_file, and long_query_time under [mysqld] in /etc/mysql/my.cnf, and restart MySQL. The procedure's example sets long_query_time to 3. Then make /var/log/mysql and the files in it readable by the Agent, and review whether the logrotate configuration targets those files.

  • Comment out the lines in mysqld_safe_syslog.cnf
  • Enable the slow query log in my.cnf and restart MySQL
  • Make /var/log/mysql readable by the Agent and review logrotate
  • Write logs_enabled in datadog.yaml and logs in mysql.d/conf.yaml, then restart the Agent
Source: Log collection in Setting Up Database Monitoring for self hosted MySQL

On the Agent side, log collection is disabled by default, so write logs_enabled: true in datadog.yaml and add the log file to mysql.d/conf.yaml.

logs:
  - type: file
    path: "<SLOW_QUERY_LOG_FILE_PATH>"
    source: mysql
    service: "<SERVICE_NAME>"
    log_processing_rules:
      - type: multi_line
        name: new_slow_query_log_entry
        pattern: "# Time:"

A single slow query log entry spans multiple lines, so add a multi_line rule that treats lines starting with # Time: as the start of an entry. Align service with the value used for Unified Service Tagging. The overall approach to collection is in the article on setting up log collection.

The monitoring user's privileges grow depending on whether you need only the integration or DBM as well

The Agent logs in to MySQL as a read-only user and collects statistics and queries. Every procedure starts by creating a user named datadog; the form datadog@'%' allows login from any host, and datadog@'localhost' restricts it to the same server. If the Agent is placed on the same server, the restricted form is enough. Rather than writing the password in plain text in the configuration file, the examples show referencing it from secrets management in the ENC[] form. The concurrent connection limit is set with MAX_USER_CONNECTIONS, written in the GRANT statement on MySQL 5.6 and in the ALTER USER statement on 5.7 and later (as of October 2026).

Main privileges to grant the datadog user (as of October 2026)
PrivilegeWhat it is used forIntegration onlyDBM
REPLICATION CLIENTReading replication statusGrantGrant
PROCESSReading running threadsGrantGrant
SELECT on performance_schema.*performance_schema statisticsGrant if performance_schema is enabledGrant
SELECT on mysql.innodb_index_statsIndex metricsWhen collecting those metricsWhen collecting those metrics
EXECUTE on the datadog schemaRunning Datadog's procedures-Grant
Source: MySQL / Setting Up Database Monitoring for self hosted MySQL

For DBM, create a datadog schema and place procedures in it. explain_statement, used to collect execution plans, is created not only in the datadog schema but also in each schema whose plans you want to collect, with execute privileges granted. The consumer procedure mentioned earlier also goes in the same schema. Every privilege in the table is limited to reading or running Datadog's procedures, which makes it easier to explain the monitoring user's role to your database administrators.

Missing preparation to suspect when screens stay empty

If some query screens stay empty even after enabling DBM, go through the preparation so far one item at a time to find what is missing. As one troubleshooting order, first check the required consumers. Running queries and wait events require the events-statements-current and events-waits-current consumers to be ON. Next, check whether the explain_statement procedure exists in schemas where execution plans do not appear. If only long SQL statements are missing, max_digest_length may still be at its default, so queries longer than 1,024 characters are not being collected (as of October 2026).

Empty screens and the preparation to suspect (as of October 2026)
What stays emptyPreparation to suspect
Running queriesThe events-statements-current consumer
Wait eventsThe events-waits-current consumer
Execution plans for a specific schemaexplain_statement in that schema and the execute privilege
Long SQL statementsmax_digest_length and the two values that should match it
Replica statusThe REPLICATION CLIENT privilege and replication in options
Organized based on Setting Up Database Monitoring for self hosted MySQL

In setups with replicas, you can list the primary and the replica as one entry each under instances in a single Agent's configuration. In the official documentation's example, replication: true under options is written only in the replica's entry, and in the standard integration's configuration example this value is false, so on replica servers rewrite it to match the example. If you can connect only through a proxy, data is recorded under the proxy's hostname, so reassign the real hostname with reported_hostname.

Once the server appears on the Databases page, the DBM path is working

This is not the order in the official documentation, but for the first server, run it with the standard integration only, without writing dbm: true, restart the Agent, and check whether mysql appears in the Checks section of the status subcommand output. If no connection or permission errors appear here, the user and network preparation is working. Next, complete the performance_schema and consumer settings, add dbm: true, and restart the Agent again. If the server appears on the Databases page in Datadog and your application's usual SQL shows up in the query list, the DBM path is working too. Add the slow query log last, and check whether queries that exceed long_query_time appear one by one in Log Explorer. Once everything shows up, there are no gaps in either the statistics path or the log path.

References

Share