<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MySQL data source on Grafana Labs</title><link>https://grafana.com/docs/grafana/v12.4/datasources/mysql/</link><description>Recent content in MySQL data source on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v12.4/datasources/mysql/index.xml" rel="self" type="application/rss+xml"/><item><title>Configure the MySQL data source</title><link>https://grafana.com/docs/grafana/v12.4/datasources/mysql/configure/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/mysql/configure/</guid><content><![CDATA[&lt;h1 id=&#34;configure-the-mysql-data-source&#34;&gt;Configure the MySQL data source&lt;/h1&gt;
&lt;p&gt;This document provides instructions for configuring the MySQL data source and explains available configuration options. For general information on managing data sources refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/data-source-management/&#34;&gt;Data source management&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before configuring the MySQL data source, ensure you have the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Grafana permissions:&lt;/strong&gt; You must have the &lt;code&gt;Organization administrator&lt;/code&gt; role to configure data sources. Organization administrators can also &lt;a href=&#34;#provision-the-data-source&#34;&gt;configure the data source via YAML&lt;/a&gt; with the Grafana provisioning system.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A running MySQL instance:&lt;/strong&gt; MySQL 5.7 or newer, MariaDB 10.2 or newer, or a compatible MySQL-based database such as Percona Server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Network access:&lt;/strong&gt; Grafana must be able to reach your MySQL server. The default port is &lt;code&gt;3306&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Authentication credentials:&lt;/strong&gt; A MySQL user with at least &lt;code&gt;SELECT&lt;/code&gt; permissions on the databases and tables you want to query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Security certificates:&lt;/strong&gt; If using encrypted connections, gather any necessary TLS/SSL certificates.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Grafana ships with a built-in MySQL data source plugin. No additional installation is required.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;



&lt;div class=&#34;admonition admonition-tip&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Tip&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Grafana Cloud users:&lt;/strong&gt; If your MySQL server is in a private network, you can configure &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect&lt;/a&gt; to establish connectivity.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;database-user-permissions&#34;&gt;Database user permissions&lt;/h3&gt;
&lt;p&gt;When adding a data source, ensure the database user you specify has only &lt;code&gt;SELECT&lt;/code&gt; permissions on the relevant database and tables. Grafana doesn&amp;rsquo;t validate the safety of queries, which means they can include potentially harmful SQL statements, such as &lt;code&gt;USE otherdb;&lt;/code&gt; or &lt;code&gt;DROP TABLE user;&lt;/code&gt;, which could get executed.&lt;/p&gt;
&lt;p&gt;To minimize this risk, Grafana strongly recommends creating a dedicated MySQL user with restricted permissions:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE USER &amp;#39;grafanaReader&amp;#39; IDENTIFIED BY &amp;#39;password&amp;#39;;
GRANT SELECT ON mydatabase.mytable TO &amp;#39;grafanaReader&amp;#39;;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Use wildcards (&lt;code&gt;*&lt;/code&gt;) in place of a database or table if you want to grant access to more databases and tables.&lt;/p&gt;
&lt;h2 id=&#34;add-the-mysql-data-source&#34;&gt;Add the MySQL data source&lt;/h2&gt;
&lt;p&gt;To add the MySQL data source complete the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;Connections&lt;/strong&gt; in the left-side menu.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add new connection&lt;/strong&gt; and type &lt;code&gt;MySQL&lt;/code&gt; in the search bar.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;MySQL data source&lt;/strong&gt; option.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add new data source&lt;/strong&gt; in the upper right.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You are taken to the &lt;strong&gt;Settings&lt;/strong&gt; tab where you will configure the data source.&lt;/p&gt;
&lt;h2 id=&#34;mysql-configuration-options&#34;&gt;MySQL configuration options&lt;/h2&gt;
&lt;p&gt;Following is a list of MySQL configuration options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Name&lt;/strong&gt; - Sets the name you use to refer to the data source in panels and queries. Examples:
&lt;code&gt;mysql-assets-1&lt;/code&gt;, &lt;code&gt;mysqldb1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Default&lt;/strong&gt; - Toggle to make this specific MySQL data source the default pre-selected data source in panels and visualizations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Connection:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Host URL&lt;/strong&gt; - Enter the IP address/hostname and optional port of your MySQL instance. If the port is omitted the default &lt;code&gt;3306&lt;/code&gt; port will be used.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Database&lt;/strong&gt; - Enter the name of your MySQL database.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Authentication:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Username&lt;/strong&gt;- Enter the username used to connect to your MySQL database.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Password&lt;/strong&gt; - Enter the password used to connect to the MySQL database.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use TLS Client Auth&lt;/strong&gt; - Toggle to enable TLS authentication using the client certificate specified in the secure JSON configuration. Refer to &lt;a href=&#34;https://dev.mysql.com/doc/refman/8.4/en/mysql-cluster-tls-using.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Using TLS Connections&lt;/a&gt; and &lt;a href=&#34;https://dev.mysql.com/doc/refman/8.4/en/using-encrypted-connections.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Configuring MySQL to Use Encrypted Connections&lt;/a&gt; for more information regarding TLS and configuring encrypted connections in MySQL. Provide the client certificate under &lt;strong&gt;TLS/SSL Client Certificate&lt;/strong&gt;. Provide the key under &lt;strong&gt;TLS/SSL Client Key&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;With CA Cert&lt;/strong&gt; - Toggle to authenticate using a CA certificate. Required for verifying self-signed TLS Certs. Follow the instructions of your CA (Certificate Authority) to download the certificate file. Provide the root certificate under &lt;strong&gt;TLS/SSL Root Certificate&lt;/strong&gt; if TLS/SSL mode requires it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Skip TLS Verification&lt;/strong&gt; - Toggle to skip verification of the MySQL server&amp;rsquo;s TLS certificate chain and host name.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Allow Cleartext Passwords&lt;/strong&gt; - Toggle to allow the use of the &lt;a href=&#34;https://dev.mysql.com/doc/en/cleartext-pluggable-authentication.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;cleartext client-side plugin&lt;/a&gt; when required by a specific type of account, such as one defined with the &lt;a href=&#34;https://dev.mysql.com/doc/refman/8.4/en/pam-pluggable-authentication.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;PAM authentication plugin&lt;/a&gt;. Note that transmitting passwords in plain text can pose a security risk in certain configurations. To prevent password-related issues, it is recommended that clients connect to a MySQL server using a secure method that protects the password. Options include &lt;a href=&#34;https://github.com/go-sql-driver/mysql#tls&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;TLS/SSL&lt;/a&gt;, IPsec, or a private network.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;additional-settings&#34;&gt;Additional settings&lt;/h2&gt;
&lt;p&gt;The following are additional MySQL settings.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;MySQL options:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Session Timezone&lt;/strong&gt; - Specifies the timezone used in the database session, such as &lt;code&gt;Europe/Berlin&lt;/code&gt; or &lt;code&gt;&#43;02:00&lt;/code&gt;. Required if the timezone of the database (or the host of the database) is set to something other than UTC. Set this to &lt;code&gt;&#43;00:00&lt;/code&gt; so Grafana can handle times properly. Set the value used in the session with &lt;code&gt;SET time_zone=&#39;...&#39;&lt;/code&gt;. If you leave this field empty, the timezone will not be updated. For more information, refer to &lt;a href=&#34;https://dev.mysql.com/doc/en/time-zone-support.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;MySQL Server Time Zone Support&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Min time interval&lt;/strong&gt; - Defines a lower limit for the 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/#__interval&#34;&gt;&lt;code&gt;$__interval&lt;/code&gt;&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/#__interval_ms&#34;&gt;&lt;code&gt;$__interval_ms&lt;/code&gt;&lt;/a&gt; variables. Grafana recommends aligning this setting with the data write frequency. For example, set it to &lt;code&gt;1m&lt;/code&gt; if your data is written every minute. Refer to &lt;a href=&#34;#min-time-interval&#34;&gt;Min time interval&lt;/a&gt; for format examples.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Connection limits:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Max open&lt;/strong&gt; - The maximum number of open connections to the database, default &lt;code&gt;100&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Max idle&lt;/strong&gt; - The maximum number of connections in the idle connection pool, default &lt;code&gt;100&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auto (max idle)&lt;/strong&gt; - Toggle to set the maximum number of idle connections to the number of maximum open connections. The default is &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Max lifetime&lt;/strong&gt; - The maximum amount of time in seconds a connection may be reused. This should always be lower than configured &lt;a href=&#34;https://dev.mysql.com/doc/en/server-system-variables.html#sysvar_wait_timeout&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;wait_timeout&lt;/a&gt; in MySQL. The default is &lt;code&gt;14400&lt;/code&gt;, or 4 hours.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Private data source connect:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Private data source connect&lt;/strong&gt; - &lt;em&gt;Only for Grafana Cloud users.&lt;/em&gt; Private data source connect, or PDC, allows you to establish a private, secured connection between a Grafana Cloud instance, or stack, and data sources secured within a private network. Click the drop-down to locate the URL for PDC. For more information regarding Grafana PDC refer to &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect (PDC)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Click &lt;strong&gt;Manage private data source connect&lt;/strong&gt; to be taken to your PDC connection page, where you’ll find your PDC configuration details.&lt;/p&gt;
&lt;p&gt;Once you have added your MySQL connection settings, click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; to test and save the data source connection.&lt;/p&gt;
&lt;h3 id=&#34;min-time-interval&#34;&gt;Min time interval&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Min time interval&lt;/strong&gt; setting defines a lower limit for the 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/#__interval&#34;&gt;&lt;code&gt;$__interval&lt;/code&gt;&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/#__interval_ms&#34;&gt;&lt;code&gt;$__interval_ms&lt;/code&gt;&lt;/a&gt; variables.&lt;/p&gt;
&lt;p&gt;This value must be formatted as a number followed by a valid time identifier:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Identifier&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;y&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;year&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;M&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;month&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;w&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;week&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;d&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;day&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;h&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;hour&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;m&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;minute&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;second&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;ms&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;millisecond&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;You can override this setting in a dashboard panel under its data source options.&lt;/p&gt;
&lt;h2 id=&#34;provision-the-data-source&#34;&gt;Provision the data source&lt;/h2&gt;
&lt;p&gt;You can define and configure the data source in YAML files as part of Grafana&amp;rsquo;s provisioning system.
For more information about provisioning, and available configuration options, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/provisioning/#data-sources&#34;&gt;Provision Grafana&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;mysql-provisioning-examples&#34;&gt;MySQL provisioning examples&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Basic provisioning:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: MySQL
    type: mysql
    url: localhost:3306
    user: grafana
    jsonData:
      database: grafana
      maxOpenConns: 100
      maxIdleConns: 100
      maxIdleConnsAuto: true
      connMaxLifetime: 14400
    secureJsonData:
      password: ${GRAFANA_MYSQL_PASSWORD}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Using TLS verification:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: MySQL
    type: mysql
    url: localhost:3306
    user: grafana
    jsonData:
      tlsAuth: true
      database: grafana
      maxOpenConns: 100
      maxIdleConns: 100
      maxIdleConnsAuto: true
      connMaxLifetime: 14400
    secureJsonData:
      password: ${GRAFANA_MYSQL_PASSWORD}
      tlsClientCert: ${GRAFANA_TLS_CLIENT_CERT}
      tlsCACert: ${GRAFANA_TLS_CA_CERT}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Use TLS and skip certificate verification:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: MySQL
    type: mysql
    url: localhost:3306
    user: grafana
    jsonData:
      tlsAuth: true
      tlsSkipVerify: true
      database: grafana
      maxOpenConns: 100
      maxIdleConns: 100
      maxIdleConnsAuto: true
      connMaxLifetime: 14400
    secureJsonData:
      password: ${GRAFANA_MYSQL_PASSWORD}
      tlsClientCert: ${GRAFANA_TLS_CLIENT_CERT}
      tlsCACert: ${GRAFANA_TLS_CA_CERT}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;configure-with-terraform&#34;&gt;Configure with Terraform&lt;/h2&gt;
&lt;p&gt;You can configure the MySQL data source using &lt;a href=&#34;https://www.terraform.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Terraform&lt;/a&gt; with the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Terraform provider&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For more information about provisioning resources with Terraform, refer to the &lt;a href=&#34;/docs/grafana-cloud/developer-resources/infrastructure-as-code/terraform/&#34;&gt;Grafana as code using Terraform&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h3 id=&#34;terraform-example&#34;&gt;Terraform example&lt;/h3&gt;
&lt;p&gt;The following example creates a basic MySQL data source:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;grafana_data_source&amp;#34; &amp;#34;mysql&amp;#34; {
  name = &amp;#34;MySQL&amp;#34;
  type = &amp;#34;mysql&amp;#34;
  url  = &amp;#34;localhost:3306&amp;#34;
  user = &amp;#34;grafana&amp;#34;

  json_data_encoded = jsonencode({
    database         = &amp;#34;grafana&amp;#34;
    maxOpenConns     = 100
    maxIdleConns     = 100
    maxIdleConnsAuto = true
    connMaxLifetime  = 14400
  })

  secure_json_data_encoded = jsonencode({
    password = &amp;#34;password&amp;#34;
  })
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For all available configuration options, refer to the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/data_source&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana provider data source resource documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;next-steps&#34;&gt;Next steps&lt;/h2&gt;
&lt;p&gt;After configuring your MySQL data source, you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/query-editor/&#34;&gt;Write queries&lt;/a&gt; using the query editor to explore and visualize your data.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/template-variables/&#34;&gt;Use template variables&lt;/a&gt; to create dynamic, reusable dashboards.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/annotations/&#34;&gt;Add annotations&lt;/a&gt; to overlay MySQL events on your graphs.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/alerting/&#34;&gt;Set up alerting&lt;/a&gt; to create alert rules based on your MySQL data.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/troubleshooting/&#34;&gt;Troubleshoot issues&lt;/a&gt; if you encounter problems with your data source.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="configure-the-mysql-data-source">Configure the MySQL data source&lt;/h1>
&lt;p>This document provides instructions for configuring the MySQL data source and explains available configuration options. For general information on managing data sources refer to
&lt;a href="/docs/grafana/v12.4/administration/data-source-management/">Data source management&lt;/a>.&lt;/p></description></item><item><title>MySQL query editor</title><link>https://grafana.com/docs/grafana/v12.4/datasources/mysql/query-editor/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/mysql/query-editor/</guid><content><![CDATA[&lt;h1 id=&#34;mysql-query-editor&#34;&gt;MySQL query editor&lt;/h1&gt;
&lt;p&gt;Grafana’s query editors are unique for each data source. For general information on Grafana query editors, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/query-transform-data/#query-editors&#34;&gt;Query editors&lt;/a&gt;. For general information on querying data sources in Grafana, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/query-transform-data/&#34;&gt;Query and transform data&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The MySQL query editor is located on the 
    &lt;a href=&#34;/docs/grafana/v12.4/explore/&#34;&gt;Explore page&lt;/a&gt;. You can also access the MySQL query editor from a dashboard panel. Click the ellipsis in the upper right of the panel and select &lt;strong&gt;Edit&lt;/strong&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;If a default database is configured in the &lt;strong&gt;Data Source Configuration page&lt;/strong&gt;, or via a provisioning configuration file, users will be restricted to querying only that pre-configured database.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;mysql-query-editor-components&#34;&gt;MySQL query editor components&lt;/h2&gt;
&lt;p&gt;The MySQL query editor has two modes: &lt;strong&gt;Builder&lt;/strong&gt; and &lt;strong&gt;Code&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Builder mode helps you build a query using a visual interface. Code mode allows for advanced querying and offers support for complex SQL query writing.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;If your table or database name contains a reserved word or a &lt;a href=&#34;https://dev.mysql.com/doc/en/identifiers.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;prohibited character&lt;/a&gt; the editor will put quotes around the name. For example, the name &lt;code&gt;table-name&lt;/code&gt; will be quoted with backticks - &lt;code&gt;`table-name`&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;mysql-builder-mode&#34;&gt;MySQL Builder mode&lt;/h2&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 1265px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/mysql/screenshot-mysql-query-editor.v11.3.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/mysql/screenshot-mysql-query-editor.v11.3.png&#34;data-srcset=&#34;/media/docs/mysql/screenshot-mysql-query-editor.v11.3.png?w=320 320w, /media/docs/mysql/screenshot-mysql-query-editor.v11.3.png?w=550 550w, /media/docs/mysql/screenshot-mysql-query-editor.v11.3.png?w=750 750w, /media/docs/mysql/screenshot-mysql-query-editor.v11.3.png?w=900 900w, /media/docs/mysql/screenshot-mysql-query-editor.v11.3.png?w=1040 1040w, /media/docs/mysql/screenshot-mysql-query-editor.v11.3.png?w=1240 1240w, /media/docs/mysql/screenshot-mysql-query-editor.v11.3.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Builder mode&#34;width=&#34;1265&#34;height=&#34;519&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/mysql/screenshot-mysql-query-editor.v11.3.png&#34;
            alt=&#34;Builder mode&#34;width=&#34;1265&#34;height=&#34;519&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;The following components will help you build a MySQL query:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Format&lt;/strong&gt; - Select a format response from the drop-down for the MySQL query. The default is &lt;strong&gt;Table&lt;/strong&gt;. If you use the &lt;strong&gt;Time series&lt;/strong&gt; format option, one of the columns must be &lt;code&gt;time&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Dataset&lt;/strong&gt; - Select a database to query from the drop-down.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Table&lt;/strong&gt; - Select a table from the drop-down. Tables correspond to the chosen database.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Data operations&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt; Select an aggregation from the drop-down. You can add multiple data operations by clicking the &lt;strong&gt;&#43; sign&lt;/strong&gt;. Click the &lt;strong&gt;X&lt;/strong&gt; to remove a data operation. Click the &lt;strong&gt;garbage can icon&lt;/strong&gt; to remove the entire column.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Column&lt;/strong&gt; - Select a column on which to run the aggregation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Alias&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt; Add an alias from the drop-down. You can also add your own alias by typing it in the box and clicking &lt;strong&gt;Enter&lt;/strong&gt;. Remove an alias by clicking the &lt;strong&gt;X&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Filter&lt;/strong&gt; - Toggle to add filters.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Filter by column value&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt; If you toggle &lt;strong&gt;Filter&lt;/strong&gt; you can add a column to filter by from the drop-down. To filter on more columns, click the &lt;strong&gt;&#43; sign&lt;/strong&gt; to the right of the condition drop-down. You can choose a variety of operators from the drop-down next to the condition. When multiple filters are added you can add an &lt;code&gt;AND&lt;/code&gt; operator to display all true conditions or an &lt;code&gt;OR&lt;/code&gt; operator to display any true conditions. Use the second drop-down to choose a filter. To remove a filter, click the &lt;code&gt;X&lt;/code&gt; button next to that filter&amp;rsquo;s drop-down. After selecting a date type column, you can choose &lt;strong&gt;Macros&lt;/strong&gt; from the operators list and select &lt;code&gt;timeFilter&lt;/code&gt; which will add the &lt;code&gt;$\_\_timeFilter&lt;/code&gt; macro to the query with the selected date column.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Group&lt;/strong&gt; - Toggle to add &lt;strong&gt;Group by column&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Group by column&lt;/strong&gt; - Select a column to filter by from the drop-down. Click the &lt;strong&gt;&#43; sign&lt;/strong&gt; to filter by multiple columns. Click the &lt;strong&gt;X&lt;/strong&gt; to remove a filter.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Order&lt;/strong&gt; - Toggle to add an ORDER BY statement.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Order by&lt;/strong&gt; - Select a column to order by from the drop-down. Select ascending (&lt;code&gt;ASC&lt;/code&gt;) or descending (&lt;code&gt;DESC&lt;/code&gt;) order.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limit&lt;/strong&gt; - You can add an optional limit on the number of retrieved results. Default is 50.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Preview&lt;/strong&gt; - Toggle for a preview of the SQL query generated by the query builder. Preview is toggled on by default.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;mysql-code-mode&#34;&gt;MySQL Code mode&lt;/h2&gt;
&lt;p&gt;To create advanced queries, switch to &lt;strong&gt;Code mode&lt;/strong&gt; by clicking &lt;strong&gt;Code&lt;/strong&gt; in the upper right of the editor window. Code mode supports the auto-completion of tables, columns, SQL keywords, standard SQL functions, Grafana template variables, and Grafana macros. Columns cannot be completed before a table has been specified.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 963px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v92/sql_code_editor.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v92/sql_code_editor.png&#34;data-srcset=&#34;/static/img/docs/v92/sql_code_editor.png?w=320 320w, /static/img/docs/v92/sql_code_editor.png?w=550 550w, /static/img/docs/v92/sql_code_editor.png?w=750 750w, /static/img/docs/v92/sql_code_editor.png?w=900 900w, /static/img/docs/v92/sql_code_editor.png?w=1040 1040w, /static/img/docs/v92/sql_code_editor.png?w=1240 1240w, /static/img/docs/v92/sql_code_editor.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;963&#34;height=&#34;326&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v92/sql_code_editor.png&#34;
            alt=&#34;&#34;width=&#34;963&#34;height=&#34;326&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;Select &lt;strong&gt;Table&lt;/strong&gt; or &lt;strong&gt;Time Series&lt;/strong&gt; as the format. Click the &lt;strong&gt;{}&lt;/strong&gt; in the bottom right to format the query. Click the &lt;strong&gt;downward caret&lt;/strong&gt; to expand the Code mode editor. &lt;strong&gt;CTRL/CMD &#43; Return&lt;/strong&gt; serves as a keyboard shortcut to execute the query.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;Changes made to a query in Code mode will not transfer to Builder mode and will be discarded. You will be prompted to copy your code to the clipboard to save any changes.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;macros&#34;&gt;Macros&lt;/h2&gt;
&lt;p&gt;You can add macros to your queries to simplify the syntax and enable dynamic elements, such as date range filters.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Macro example&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__time(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with an expression to convert to a UNIX timestamp and renames the column to &lt;code&gt;time_sec&lt;/code&gt;. It also helps to recognize the &lt;code&gt;time&lt;/code&gt; column, as required in Time Series format. Example: &lt;em&gt;UNIX_TIMESTAMP(dateColumn) AS time_sec&lt;/em&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeEpoch(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with an expression to convert to a UNIX Epoch timestamp and renames the column to &lt;code&gt;time_sec&lt;/code&gt;. Example: &lt;em&gt;UNIX_TIMESTAMP(dateColumn) AS time_sec&lt;/em&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Applies a time range filter using the specified column name and fetches only the data that falls within that range. Example: &lt;em&gt;dateColumn BETWEEN FROM_UNIXTIME(1494410783) AND FROM_UNIXTIME(1494410983)&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the start of the currently active time selection. Example: &lt;em&gt;FROM_UNIXTIME(1494410783)&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the end of the currently active time selection. Example: &lt;em&gt;FROM_UNIXTIME(1494410983)&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with an expression suitable for use in a GROUP BY clause and creates the bucket timestamps at a fixed interval. Example: *cast(cast(UNIX_TIMESTAMP(dateColumn)/(300) as signed)*300 as signed),*&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, 0)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as the &lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;)&lt;/code&gt; macro, but includes a fill parameter to ensure missing points in the series are added by Grafana, using 0 as the default value. &lt;strong&gt;This applies only to time series queries.&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, NULL)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as the &lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, 0)&lt;/code&gt; but NULL is used as the value for missing points. &lt;strong&gt;This applies only to time series queries.&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, previous)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as the &lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, previous)&lt;/code&gt; macro, but uses the previous value in the series as the fill value. If no previous value exists,&lt;code&gt;NULL&lt;/code&gt; will be used. &lt;strong&gt;This applies only to time series queries.&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroupAlias(dateColumn,&#39;5m&#39;)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value identical to $__timeGroup but with an added column alias.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value by a time range filter using the specified column name with times represented as a UNIX timestamp. Example: &lt;em&gt;dateColumn &amp;gt; 1494410783 AND dateColumn &amp;lt; 1494497183&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the start of the currently active time selection as a UNIX timestamp. Example: &lt;em&gt;1494410783&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the end of the currently active time selection as UNIX timestamp. Example: &lt;em&gt;1494497183&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with a time range filter using the specified column name with time represented as a nanosecond timestamp. Example: &lt;em&gt;dateColumn &amp;gt; 1494410783152415214 AND dateColumn &amp;lt; 1494497183142514872&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the start of the currently active time selection as nanosecond timestamp. Example: &lt;em&gt;1494410783152415214&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the end of the currently active time selection as nanosecond timestamp. Example: &lt;em&gt;1494497183142514872&lt;/em&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochGroup(dateColumn,&#39;5m&#39;, [fillmode])&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as $__timeGroup but for times stored as Unix timestamp. &lt;strong&gt;Note that &lt;code&gt;fillMode&lt;/code&gt; only works with time series queries.&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochGroupAlias(dateColumn,&#39;5m&#39;, [fillmode])&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as $__timeGroup but also adds a column alias. &lt;strong&gt;Note that &lt;code&gt;fillMode&lt;/code&gt; only works with time series queries.&lt;/strong&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;table-sql-queries&#34;&gt;Table SQL queries&lt;/h2&gt;
&lt;p&gt;If the &lt;strong&gt;Format&lt;/strong&gt; option is set to &lt;strong&gt;Table&lt;/strong&gt;, you can execute virtually any type of SQL query. The Table panel will automatically display the resulting columns and rows from your query.&lt;/p&gt;
&lt;p&gt;You can change or customize the name of a Table panel column by using the SQL keyword &lt;code&gt;AS&lt;/code&gt; syntax.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  title as &amp;#39;Title&amp;#39;,
  user.login as &amp;#39;Created By&amp;#39; ,
  dashboard.created as &amp;#39;Created On&amp;#39;
 FROM dashboard
INNER JOIN user on user.id = dashboard.created_by
WHERE $__timeFilter(dashboard.created)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Table panel results:&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload&#34;
  data-src=&#34;/static/img/docs/v43/mysql_table.png&#34;
  alt=&#34;&#34; width=&#34;562&#34;
     height=&#34;250&#34;/&gt;&lt;/p&gt;
&lt;h2 id=&#34;time-series-queries&#34;&gt;Time series queries&lt;/h2&gt;
&lt;p&gt;Set the &lt;strong&gt;Format&lt;/strong&gt; option to &lt;strong&gt;Time series&lt;/strong&gt; to create and run time series queries.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;To run a time series query you must include a column named &lt;code&gt;time&lt;/code&gt; that returns either a SQL datetime value or a numeric datatype representing the UNIX epoch time in seconds. Additionally, the query results must be sorted by the &lt;code&gt;time&lt;/code&gt; column for proper visualization in panels.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The examples in this section refer to the data in the following table:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;&amp;#43;---------------------&amp;#43;--------------&amp;#43;---------------------&amp;#43;----------&amp;#43;
| time_date_time      | value_double | CreatedAt           | hostname |
&amp;#43;---------------------&amp;#43;--------------&amp;#43;---------------------&amp;#43;----------&amp;#43;
| 2025-01-02 03:05:00 | 3.0          | 2025-01-02 03:05:00 | 10.0.1.1 |
| 2025-01-02 03:06:00 | 4.0          | 2025-01-02 03:06:00 | 10.0.1.2 |
| 2025-01-02 03:10:00 | 6.0          | 2025-01-02 03:10:00 | 10.0.1.1 |
| 2025-01-02 03:11:00 | 7.0          | 2025-01-02 03:11:00 | 10.0.1.2 |
| 2025-01-02 03:20:00 | 5.0          | 2025-01-02 03:20:00 | 10.0.1.2 |
&amp;#43;---------------------&amp;#43;--------------&amp;#43;---------------------&amp;#43;----------&amp;#43;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;For backward compatibility, an exception to the aforementioned rule applies to queries returning three columns, including a string column named &lt;code&gt;metric&lt;/code&gt;. Instead of converting the metric column into field labels, it is used as the field name, and the series name is set to the value of the metric column. Refer to the following example with a metric column.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Example with &lt;code&gt;$__time(dateColumn)&lt;/code&gt; Macro:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__time(time_date_time),
  value_double
FROM my_data
ORDER BY time_date_time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Table panel result:&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 624px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png&#34;data-srcset=&#34;/media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=320 320w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=550 550w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=750 750w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=900 900w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=1040 1040w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=1240 1240w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;output of time macro&#34;width=&#34;624&#34;height=&#34;233&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png&#34;
            alt=&#34;output of time macro&#34;width=&#34;624&#34;height=&#34;233&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;In the following example, the result includes two columns, &lt;code&gt;Time&lt;/code&gt; and &lt;code&gt;value_double&lt;/code&gt;, which represent the data associated with fixed timestamps. This query does not apply a time range filter and returns all rows from the table.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example with &lt;code&gt;$__timeFilter(dateColumn)&lt;/code&gt; Macro:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__time(time_date_time),
  value_double
FROM my_data
WHERE $__timeFilter(time_date_time)
ORDER BY time_date_time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Table panel result:&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 624px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png&#34;data-srcset=&#34;/media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=320 320w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=550 550w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=750 750w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=900 900w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=1040 1040w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=1240 1240w, /media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;output of time filter macro&#34;width=&#34;624&#34;height=&#34;233&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-time-and-timefilter-macro.png&#34;
            alt=&#34;output of time filter macro&#34;width=&#34;624&#34;height=&#34;233&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;This example returns the same result as the previous one, but adds support for filtering data using the Grafana time picker.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example with &lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;)&lt;/code&gt; Macro:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroup(time_date_time, &amp;#39;5m&amp;#39;) AS time,
  sum(value_double) AS sum_value
FROM my_data
WHERE $__timeFilter(time_date_time)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Table panel result:&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 624px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png&#34;data-srcset=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png?w=320 320w, /media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png?w=550 550w, /media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png?w=750 750w, /media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png?w=900 900w, /media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png?w=1040 1040w, /media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png?w=1240 1240w, /media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;output of time group macro&#34;width=&#34;624&#34;height=&#34;127&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timegroup-macro.png&#34;
            alt=&#34;output of time group macro&#34;width=&#34;624&#34;height=&#34;127&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;Given the result in the following example, the data is grouped and aggregated within buckets with timestamps of fixed interval i.e. 5 mins. To customize the default series name formatting (optional), refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/configure-standard-options/&#34;&gt;Standard options definitions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example with &lt;code&gt;$__timeGroupAlias(dateColumn,&#39;5m&#39;)&lt;/code&gt; Macro:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(time_date_time,&amp;#39;5m&amp;#39;),
  min(value_double),
  &amp;#39;min&amp;#39; as metric
FROM my_data
WHERE $__timeFilter(time_date_time)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Table panel result:&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 624px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png&#34;data-srcset=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png?w=320 320w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png?w=550 550w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png?w=750 750w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png?w=900 900w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png?w=1040 1040w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png?w=1240 1240w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;output of time group alias macro&#34;width=&#34;624&#34;height=&#34;117&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro.png&#34;
            alt=&#34;output of time group alias macro&#34;width=&#34;624&#34;height=&#34;117&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;The following result is similar to the result of the &lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;)&lt;/code&gt; macro, except it uses a built-in alias for the time column.
To customize the default series name formatting (optional), refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/configure-standard-options/&#34;&gt;Standard options definitions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example with &lt;code&gt;$__timeGroupAlias&lt;/code&gt; Macro to convert null values to zero instead:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(createdAt,&amp;#39;5m&amp;#39;,0),
  sum(value_double) as value,
  hostname
FROM my_data
WHERE
  $__timeFilter(createdAt)
GROUP BY time, hostname
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Table panel result:&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 624px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png&#34;data-srcset=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png?w=320 320w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png?w=550 550w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png?w=750 750w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png?w=900 900w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png?w=1040 1040w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png?w=1240 1240w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;output of null values to zero case, for time group alias macro&#34;width=&#34;624&#34;height=&#34;159&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-conv-null-to-zero.png&#34;
            alt=&#34;output of null values to zero case, for time group alias macro&#34;width=&#34;624&#34;height=&#34;159&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;Given the result in the following example, null values within bucket timestamps are replaced by zero and also add the &lt;code&gt;Time&lt;/code&gt; column alias by default. To customize the default series name formatting (optional), refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/configure-standard-options/&#34;&gt;Standard options definitions&lt;/a&gt; to display the value of &lt;code&gt;${__field.labels.hostname}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example with multiple columns for &lt;code&gt;$__timeGroupAlias(dateColumn,&#39;5m&#39;)&lt;/code&gt; Macro:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(time_date_time,&amp;#39;5m&amp;#39;),
  min(value_double) as min_value,
  max(value_double) as max_value
FROM my_data
WHERE $__timeFilter(time_date_time)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Table panel result:&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 624px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png&#34;data-srcset=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png?w=320 320w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png?w=550 550w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png?w=750 750w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png?w=900 900w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png?w=1040 1040w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png?w=1240 1240w, /media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;output with multiple colummns for time group alias macro&#34;width=&#34;624&#34;height=&#34;143&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana/data-sources/mysql/screenshot-timeGroupAlias-macro-multiple-columns.png&#34;
            alt=&#34;output with multiple colummns for time group alias macro&#34;width=&#34;624&#34;height=&#34;143&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;The query returns multiple columns representing minimum and maximum values within the defined range.&lt;/p&gt;
&lt;h2 id=&#34;template-variables&#34;&gt;Template variables&lt;/h2&gt;
&lt;p&gt;Instead of hard-coding values like server, application, or sensor names in your metric queries, you can use variables. Variables appear as drop-down select boxes at the top of the dashboard, making it easy to change the data displayed in your dashboard.&lt;/p&gt;
&lt;p&gt;For detailed information on using template variables with MySQL, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/template-variables/&#34;&gt;MySQL template variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;annotations&#34;&gt;Annotations&lt;/h2&gt;
&lt;p&gt;Annotations allow you to overlay event information on your graphs, helping you correlate events with metrics. You can write SQL queries that return event data to display as annotations on your dashboards.&lt;/p&gt;
&lt;p&gt;For detailed information on creating annotations with MySQL, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/annotations/&#34;&gt;MySQL annotations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;alerting&#34;&gt;Alerting&lt;/h2&gt;
&lt;p&gt;You can use time series queries to create Grafana-managed alert rules. Table formatted queries are not supported in alert rule conditions.&lt;/p&gt;
&lt;p&gt;For detailed information on creating alerts with MySQL, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/alerting/&#34;&gt;MySQL alerting&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="mysql-query-editor">MySQL query editor&lt;/h1>
&lt;p>Grafana’s query editors are unique for each data source. For general information on Grafana query editors, refer to
&lt;a href="/docs/grafana/v12.4/panels-visualizations/query-transform-data/#query-editors">Query editors&lt;/a>. For general information on querying data sources in Grafana, refer to
&lt;a href="/docs/grafana/v12.4/panels-visualizations/query-transform-data/">Query and transform data&lt;/a>.&lt;/p></description></item><item><title>MySQL template variables</title><link>https://grafana.com/docs/grafana/v12.4/datasources/mysql/template-variables/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/mysql/template-variables/</guid><content><![CDATA[&lt;h1 id=&#34;mysql-template-variables&#34;&gt;MySQL template variables&lt;/h1&gt;
&lt;p&gt;Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana displays these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as &lt;strong&gt;template variables&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For an introduction to templating and template variables, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/&#34;&gt;Templating&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/&#34;&gt;Add and manage variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;query-variable&#34;&gt;Query variable&lt;/h2&gt;
&lt;p&gt;A query variable in Grafana dynamically retrieves values from your data source using a query. With a query variable, you can write a SQL query that returns values such as measurement names, key names, or key values that are shown in a drop-down select box.&lt;/p&gt;
&lt;p&gt;For example, the following query returns all values from the &lt;code&gt;hostname&lt;/code&gt; column:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM my_host&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;A query can return multiple columns, and Grafana automatically generates a list using the values from those columns. For example, the following query returns values from both the &lt;code&gt;hostname&lt;/code&gt; and &lt;code&gt;hostname2&lt;/code&gt; columns, which are included in the variable&amp;rsquo;s drop-down list.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT my_host.hostname, my_other_host.hostname2 FROM my_host JOIN my_other_host ON my_host.city = my_other_host.city&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To use time range dependent macros like &lt;code&gt;$__timeFilter(column)&lt;/code&gt; in your query, you must set the template variable&amp;rsquo;s refresh mode to &lt;strong&gt;On Time Range Change&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT event_name FROM event_log WHERE $__timeFilter(time_column)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;keyvalue-variables&#34;&gt;Key/value variables&lt;/h3&gt;
&lt;p&gt;You can create a key/value variable using a query that returns two columns named &lt;code&gt;__text&lt;/code&gt; and &lt;code&gt;__value&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;__text&lt;/code&gt; column defines the label shown in the drop-down.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;__value&lt;/code&gt; column defines the value passed to panel queries.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is useful when you want to display a user-friendly label (like a hostname) but use a different underlying value (like an ID).&lt;/p&gt;
&lt;p&gt;Note that the values in the &lt;code&gt;__text&lt;/code&gt; column should be unique. If there are duplicates, Grafana uses only the first matching entry.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname AS __text, id AS __value FROM my_host&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;nested-variables&#34;&gt;Nested variables&lt;/h3&gt;
&lt;p&gt;You can create nested variables, where one variable depends on the value of another. For example, if you have a variable named &lt;code&gt;region&lt;/code&gt;, you can configure a &lt;code&gt;hosts&lt;/code&gt; variable to only show hosts from the selected region. If &lt;code&gt;region&lt;/code&gt; is a multi-value variable, use the &lt;code&gt;IN&lt;/code&gt; operator instead of &lt;code&gt;=&lt;/code&gt; to match against multiple selected values.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM my_host WHERE region IN($region)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;filter-results-with-__searchfilter&#34;&gt;Filter results with &lt;code&gt;__searchFilter&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Using &lt;code&gt;__searchFilter&lt;/code&gt; in the query field allows the query results to be filtered based on the user&amp;rsquo;s input in the drop-down selection box. If you don&amp;rsquo;t enter anything, the default value for &lt;code&gt;__searchFilter&lt;/code&gt; is &lt;code&gt;%&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Note that you must enclose the &lt;code&gt;__searchFilter&lt;/code&gt; expression in quotes as Grafana doesn&amp;rsquo;t add them automatically.&lt;/p&gt;
&lt;p&gt;The following example demonstrates how to use &lt;code&gt;__searchFilter&lt;/code&gt; in the query field to enable real-time searching for &lt;code&gt;hostname&lt;/code&gt; as the user types in the drop-down selection box.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM my_host WHERE hostname LIKE &amp;#39;$__searchFilter&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;use-variables-in-queries&#34;&gt;Use variables in queries&lt;/h2&gt;
&lt;p&gt;Grafana automatically quotes template variable values only when the template variable is a &lt;code&gt;multi-value&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When using a multi-value variable, use the &lt;code&gt;IN&lt;/code&gt; comparison operator instead of &lt;code&gt;=&lt;/code&gt; to match against multiple values.&lt;/p&gt;
&lt;p&gt;Grafana supports two syntaxes for using variables in queries:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;$&amp;lt;varname&amp;gt;&lt;/code&gt; syntax&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example with a template variable named &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  UNIX_TIMESTAMP(atimestamp) as time,
  aint as value,
  avarchar as metric
FROM my_table
WHERE $__timeFilter(atimestamp) and hostname in($hostname)
ORDER BY atimestamp ASC&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;[[varname]]&lt;/code&gt; syntax&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example with a template variable named &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  UNIX_TIMESTAMP(atimestamp) as time,
  aint as value,
  avarchar as metric
FROM my_table
WHERE $__timeFilter(atimestamp) and hostname in([[hostname]])
ORDER BY atimestamp ASC&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;disable-quoting-for-multi-value-variables&#34;&gt;Disable quoting for multi-value variables&lt;/h3&gt;
&lt;p&gt;By default, Grafana formats multi-value variables as a quoted, comma-separated string. For example, if &lt;code&gt;server01&lt;/code&gt; and &lt;code&gt;server02&lt;/code&gt; are selected, the result will be &lt;code&gt;&#39;server01&#39;&lt;/code&gt;, &lt;code&gt;&#39;server02&#39;&lt;/code&gt;. To disable quoting, use the &lt;code&gt;csv&lt;/code&gt; formatting option for variables:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;${servers:csv}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This outputs the values as an unquoted comma-separated list.&lt;/p&gt;
&lt;p&gt;Refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/variable-syntax/#advanced-variable-format-options&#34;&gt;Advanced variable format options&lt;/a&gt; for additional information.&lt;/p&gt;
]]></content><description>&lt;h1 id="mysql-template-variables">MySQL template variables&lt;/h1>
&lt;p>Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana displays these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as &lt;strong>template variables&lt;/strong>.&lt;/p></description></item><item><title>MySQL annotations</title><link>https://grafana.com/docs/grafana/v12.4/datasources/mysql/annotations/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/mysql/annotations/</guid><content><![CDATA[&lt;h1 id=&#34;mysql-annotations&#34;&gt;MySQL annotations&lt;/h1&gt;
&lt;p&gt;Annotations overlay event data on your dashboard graphs, helping you correlate events with metrics.
You can use MySQL as a data source for annotations to display events such as deployments, alerts, or other significant occurrences on your visualizations.&lt;/p&gt;
&lt;p&gt;For general information about annotations, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/build-dashboards/annotate-visualizations/&#34;&gt;Annotate visualizations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before creating MySQL annotations, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A MySQL data source configured in Grafana.&lt;/li&gt;
&lt;li&gt;Tables containing event data with timestamp fields.&lt;/li&gt;
&lt;li&gt;Read access to the tables containing your events.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;create-an-annotation-query&#34;&gt;Create an annotation query&lt;/h2&gt;
&lt;p&gt;To add a MySQL annotation to your dashboard:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to your dashboard and click &lt;strong&gt;Dashboard settings&lt;/strong&gt; (gear icon).&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Annotations&lt;/strong&gt; in the left menu.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add annotation query&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a &lt;strong&gt;Name&lt;/strong&gt; for the annotation.&lt;/li&gt;
&lt;li&gt;Select your &lt;strong&gt;MySQL&lt;/strong&gt; data source from the &lt;strong&gt;Data source&lt;/strong&gt; drop-down.&lt;/li&gt;
&lt;li&gt;Write a SQL query that returns the required columns.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;query-columns&#34;&gt;Query columns&lt;/h2&gt;
&lt;p&gt;Your annotation query must return a &lt;code&gt;time&lt;/code&gt; column and can optionally include &lt;code&gt;timeend&lt;/code&gt;, &lt;code&gt;text&lt;/code&gt;, and &lt;code&gt;tags&lt;/code&gt; columns.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Column&lt;/th&gt;
              &lt;th&gt;Required&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;time&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;The timestamp for the annotation. Can be a SQL datetime or UNIX epoch value.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;timeend&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;The end timestamp for range annotations. Creates a shaded region instead of a vertical line.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;text&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;The annotation description displayed when you hover over the annotation.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tags&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Tags for the annotation as a comma-separated string. Helps categorize and filter annotations.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example-queries&#34;&gt;Example queries&lt;/h2&gt;
&lt;p&gt;The following examples show common annotation query patterns.&lt;/p&gt;
&lt;h3 id=&#34;basic-annotation-with-epoch-time&#34;&gt;Basic annotation with epoch time&lt;/h3&gt;
&lt;p&gt;Display events using UNIX epoch timestamps:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  epoch_time as time,
  description as text,
  CONCAT(tag1, &amp;#39;,&amp;#39;, tag2) as tags
FROM events
WHERE $__unixEpochFilter(epoch_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;annotation-with-a-single-tag&#34;&gt;Annotation with a single tag&lt;/h3&gt;
&lt;p&gt;Display events with a single tag value:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  epoch_time as time,
  message as text,
  category as tags
FROM event_log
WHERE $__unixEpochFilter(epoch_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;range-annotation-with-start-and-end-time&#34;&gt;Range annotation with start and end time&lt;/h3&gt;
&lt;p&gt;Display events with duration as shaded regions:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  start_time as time,
  end_time as timeend,
  description as text,
  CONCAT(type, &amp;#39;,&amp;#39;, severity) as tags
FROM incidents
WHERE $__unixEpochFilter(start_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;annotation-with-native-sql-datetime&#34;&gt;Annotation with native SQL datetime&lt;/h3&gt;
&lt;p&gt;Display events using native MySQL datetime columns:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  event_date as time,
  message as text,
  CONCAT(category, &amp;#39;,&amp;#39;, priority) as tags
FROM system_events
WHERE $__timeFilter(event_date)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;deployment-annotations&#34;&gt;Deployment annotations&lt;/h3&gt;
&lt;p&gt;Display deployment events:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  deployed_at as time,
  CONCAT(&amp;#39;Deployed &amp;#39;, version, &amp;#39; to &amp;#39;, environment) as text,
  environment as tags
FROM deployments
WHERE $__timeFilter(deployed_at)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;maintenance-window-annotations&#34;&gt;Maintenance window annotations&lt;/h3&gt;
&lt;p&gt;Display maintenance windows as range annotations:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  start_time as time,
  end_time as timeend,
  CONCAT(&amp;#39;Maintenance: &amp;#39;, description) as text,
  &amp;#39;maintenance&amp;#39; as tags
FROM maintenance_windows
WHERE $__timeFilter(start_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;macros&#34;&gt;Macros&lt;/h2&gt;
&lt;p&gt;Use these macros in your annotation queries to filter by the dashboard time range:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Macro&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFilter(column)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filters by time range using a native SQL datetime column.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFilter(column)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filters by time range using a column with UNIX epoch timestamps.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;p&gt;Follow these best practices when creating MySQL annotations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use time filters:&lt;/strong&gt; Always include &lt;code&gt;$__timeFilter()&lt;/code&gt; or &lt;code&gt;$__unixEpochFilter()&lt;/code&gt; to limit results to the dashboard time range.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep queries efficient:&lt;/strong&gt; Add indexes on time columns and filter columns to improve query performance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use meaningful text:&lt;/strong&gt; Include descriptive information in the &lt;code&gt;text&lt;/code&gt; column to make annotations useful.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Organize with tags:&lt;/strong&gt; Use consistent tag values to categorize annotations and enable filtering.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test queries first:&lt;/strong&gt; Verify your query returns expected results in Explore before adding it as an annotation.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="mysql-annotations">MySQL annotations&lt;/h1>
&lt;p>Annotations overlay event data on your dashboard graphs, helping you correlate events with metrics.
You can use MySQL as a data source for annotations to display events such as deployments, alerts, or other significant occurrences on your visualizations.&lt;/p></description></item><item><title>MySQL alerting</title><link>https://grafana.com/docs/grafana/v12.4/datasources/mysql/alerting/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/mysql/alerting/</guid><content><![CDATA[&lt;h1 id=&#34;mysql-alerting&#34;&gt;MySQL alerting&lt;/h1&gt;
&lt;p&gt;You can use Grafana Alerting with MySQL to create alerts based on your MySQL data. This allows you to monitor metrics, detect anomalies, and receive notifications when specific conditions are met.&lt;/p&gt;
&lt;p&gt;For general information about Grafana Alerting, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/&#34;&gt;Grafana Alerting&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before creating alerts with MySQL, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A MySQL data source configured in Grafana.&lt;/li&gt;
&lt;li&gt;Appropriate permissions to create alert rules.&lt;/li&gt;
&lt;li&gt;Understanding of the metrics you want to monitor.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;supported-query-types&#34;&gt;Supported query types&lt;/h2&gt;
&lt;p&gt;MySQL alerting works with &lt;strong&gt;time series queries&lt;/strong&gt; that return numeric data over time. Table formatted queries are not supported in alert rule conditions.&lt;/p&gt;
&lt;p&gt;To create a valid alert query:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Include a &lt;code&gt;time&lt;/code&gt; column that returns a SQL datetime or UNIX epoch timestamp&lt;/li&gt;
&lt;li&gt;Return numeric values for the metrics you want to alert on&lt;/li&gt;
&lt;li&gt;Sort results by the time column&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information on writing time series queries, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/mysql/query-editor/&#34;&gt;MySQL query editor&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;query-format-requirements&#34;&gt;Query format requirements&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Query format&lt;/th&gt;
              &lt;th&gt;Alerting support&lt;/th&gt;
              &lt;th&gt;Notes&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Time series&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;Required for alerting&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Table&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Convert to time series format for alerts&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;create-an-alert-rule&#34;&gt;Create an alert rule&lt;/h2&gt;
&lt;p&gt;To create an alert rule using MySQL:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Alerting&lt;/strong&gt; &amp;gt; &lt;strong&gt;Alert rules&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;New alert rule&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a name for the alert rule.&lt;/li&gt;
&lt;li&gt;Select your &lt;strong&gt;MySQL&lt;/strong&gt; data source.&lt;/li&gt;
&lt;li&gt;Build your query using the query editor:
&lt;ul&gt;
&lt;li&gt;Set the &lt;strong&gt;Format&lt;/strong&gt; to &lt;strong&gt;Time series&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Include a time column using the &lt;code&gt;$__time()&lt;/code&gt; or &lt;code&gt;$__timeGroup()&lt;/code&gt; macro&lt;/li&gt;
&lt;li&gt;Add numeric columns for the values to monitor&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;$__timeFilter()&lt;/code&gt; to filter data by the dashboard time range&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Configure the alert condition (for example, when the average is above a threshold).&lt;/li&gt;
&lt;li&gt;Set the evaluation interval and pending period.&lt;/li&gt;
&lt;li&gt;Configure notifications and labels.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save rule&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For detailed instructions, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/alerting-rules/create-grafana-managed-rule/&#34;&gt;Create a Grafana-managed alert rule&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example-alert-queries&#34;&gt;Example alert queries&lt;/h2&gt;
&lt;p&gt;The following examples show common alerting scenarios with MySQL.&lt;/p&gt;
&lt;h3 id=&#34;alert-on-high-error-count&#34;&gt;Alert on high error count&lt;/h3&gt;
&lt;p&gt;Monitor the number of errors over time:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroup(created_at, &amp;#39;1m&amp;#39;) AS time,
  COUNT(*) AS error_count
FROM error_logs
WHERE $__timeFilter(created_at)
  AND level = &amp;#39;error&amp;#39;
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When error_count is above 100.&lt;/p&gt;
&lt;h3 id=&#34;alert-on-average-response-time&#34;&gt;Alert on average response time&lt;/h3&gt;
&lt;p&gt;Monitor API response times:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroup(request_time, &amp;#39;5m&amp;#39;) AS time,
  AVG(response_time_ms) AS avg_response_time
FROM api_requests
WHERE $__timeFilter(request_time)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When avg_response_time is above 500 (milliseconds).&lt;/p&gt;
&lt;h3 id=&#34;alert-on-low-order-volume&#34;&gt;Alert on low order volume&lt;/h3&gt;
&lt;p&gt;Detect drops in order activity:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroup(order_date, &amp;#39;1h&amp;#39;) AS time,
  COUNT(*) AS order_count
FROM orders
WHERE $__timeFilter(order_date)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When order_count is below 10.&lt;/p&gt;
&lt;h3 id=&#34;alert-on-disk-usage-percentage&#34;&gt;Alert on disk usage percentage&lt;/h3&gt;
&lt;p&gt;Monitor database storage metrics:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroup(recorded_at, &amp;#39;5m&amp;#39;) AS time,
  AVG(disk_used_percent) AS disk_usage
FROM system_metrics
WHERE $__timeFilter(recorded_at)
  AND metric_type = &amp;#39;disk&amp;#39;
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When disk_usage is above 85.&lt;/p&gt;
&lt;h2 id=&#34;limitations&#34;&gt;Limitations&lt;/h2&gt;
&lt;p&gt;When using MySQL with Grafana Alerting, be aware of the following limitations:&lt;/p&gt;
&lt;h3 id=&#34;template-variables-not-supported&#34;&gt;Template variables not supported&lt;/h3&gt;
&lt;p&gt;Alert queries cannot contain template variables. Grafana evaluates alert rules on the backend without dashboard context, so variables like &lt;code&gt;$hostname&lt;/code&gt; or &lt;code&gt;$environment&lt;/code&gt; won&amp;rsquo;t be resolved.&lt;/p&gt;
&lt;p&gt;If your dashboard query uses template variables, create a separate query for alerting with hard coded values.&lt;/p&gt;
&lt;h3 id=&#34;table-format-not-supported&#34;&gt;Table format not supported&lt;/h3&gt;
&lt;p&gt;Queries using the &lt;strong&gt;Table&lt;/strong&gt; format cannot be used for alerting. Set the query format to &lt;strong&gt;Time series&lt;/strong&gt; and ensure your query returns a time column.&lt;/p&gt;
&lt;h3 id=&#34;query-timeout&#34;&gt;Query timeout&lt;/h3&gt;
&lt;p&gt;Complex queries with large datasets may timeout during alert evaluation. Optimize queries for alerting by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Adding appropriate &lt;code&gt;WHERE&lt;/code&gt; clauses to limit data&lt;/li&gt;
&lt;li&gt;Using indexes on time and filter columns&lt;/li&gt;
&lt;li&gt;Reducing the time range evaluated&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;p&gt;Follow these best practices when creating MySQL alerts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use time series format:&lt;/strong&gt; Always set the query format to Time series for alert queries.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Include time filters:&lt;/strong&gt; Use the &lt;code&gt;$__timeFilter()&lt;/code&gt; macro to limit data to the evaluation window.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Optimize queries:&lt;/strong&gt; Add indexes on columns used in &lt;code&gt;WHERE&lt;/code&gt; clauses and &lt;code&gt;GROUP BY&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test queries first:&lt;/strong&gt; Verify your query returns expected results in Explore before creating an alert.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Set realistic thresholds:&lt;/strong&gt; Base alert thresholds on historical data patterns.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use meaningful names:&lt;/strong&gt; Give alert rules descriptive names that indicate what they monitor.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="mysql-alerting">MySQL alerting&lt;/h1>
&lt;p>You can use Grafana Alerting with MySQL to create alerts based on your MySQL data. This allows you to monitor metrics, detect anomalies, and receive notifications when specific conditions are met.&lt;/p></description></item><item><title>Troubleshoot MySQL data source issues</title><link>https://grafana.com/docs/grafana/v12.4/datasources/mysql/troubleshooting/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/mysql/troubleshooting/</guid><content><![CDATA[&lt;h1 id=&#34;troubleshoot-mysql-data-source-issues&#34;&gt;Troubleshoot MySQL data source issues&lt;/h1&gt;
&lt;p&gt;This document provides solutions to common issues you may encounter when configuring or using the MySQL data source in Grafana.&lt;/p&gt;
&lt;h2 id=&#34;connection-errors&#34;&gt;Connection errors&lt;/h2&gt;
&lt;p&gt;These errors occur when Grafana cannot establish or maintain a connection to the MySQL server.&lt;/p&gt;
&lt;h3 id=&#34;unable-to-connect-to-the-server&#34;&gt;Unable to connect to the server&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;dial tcp: connection refused&amp;rdquo; or &amp;ldquo;Could not connect to MySQL&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana cannot establish a network connection to the MySQL server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the MySQL server is running and accessible.&lt;/li&gt;
&lt;li&gt;Check that the host and port are correct in the data source configuration. The default MySQL port is &lt;code&gt;3306&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ensure there are no firewall rules blocking the connection between Grafana and MySQL.&lt;/li&gt;
&lt;li&gt;Verify that MySQL is configured to allow remote connections by checking the &lt;code&gt;bind-address&lt;/code&gt; setting in your MySQL configuration.&lt;/li&gt;
&lt;li&gt;For Grafana Cloud, ensure you have configured &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect&lt;/a&gt; if your MySQL instance isn&amp;rsquo;t publicly accessible.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;connection-timeout&#34;&gt;Connection timeout&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Connection timed out&amp;rdquo; or &amp;ldquo;I/O timeout&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The connection to MySQL timed out before receiving a response.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the network latency between Grafana and MySQL.&lt;/li&gt;
&lt;li&gt;Verify that MySQL isn&amp;rsquo;t overloaded or experiencing performance issues.&lt;/li&gt;
&lt;li&gt;Check if any network devices (load balancers, proxies) are timing out the connection.&lt;/li&gt;
&lt;li&gt;Increase the &lt;code&gt;wait_timeout&lt;/code&gt; setting in MySQL if connections are timing out during idle periods.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;tlsssl-connection-failures&#34;&gt;TLS/SSL connection failures&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;TLS handshake failed&amp;rdquo; or &amp;ldquo;x509: certificate verify failed&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; There is a mismatch between the TLS settings in Grafana and what the MySQL server supports or requires.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the MySQL server has a valid SSL certificate if encryption is enabled.&lt;/li&gt;
&lt;li&gt;Check that the certificate is trusted by the Grafana server.&lt;/li&gt;
&lt;li&gt;If using a self-signed certificate, enable &lt;strong&gt;With CA Cert&lt;/strong&gt; and provide the root certificate under &lt;strong&gt;TLS/SSL Root Certificate&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To bypass certificate validation (not recommended for production), enable &lt;strong&gt;Skip TLS Verification&lt;/strong&gt; in the data source configuration.&lt;/li&gt;
&lt;li&gt;Ensure the SSL certificate hasn&amp;rsquo;t expired.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;connection-reset-by-peer&#34;&gt;Connection reset by peer&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Connection reset by peer&amp;rdquo; or &amp;ldquo;EOF&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The MySQL server closed the connection unexpectedly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the &lt;code&gt;max_connections&lt;/code&gt; setting on the MySQL server to ensure it isn&amp;rsquo;t being exceeded.&lt;/li&gt;
&lt;li&gt;Verify the &lt;code&gt;wait_timeout&lt;/code&gt; and &lt;code&gt;interactive_timeout&lt;/code&gt; settings in MySQL aren&amp;rsquo;t set too low.&lt;/li&gt;
&lt;li&gt;Increase the &lt;strong&gt;Max lifetime&lt;/strong&gt; setting in Grafana&amp;rsquo;s data source configuration to be lower than the MySQL &lt;code&gt;wait_timeout&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check MySQL server logs for any errors or connection-related messages.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;authentication-errors&#34;&gt;Authentication errors&lt;/h2&gt;
&lt;p&gt;These errors occur when there are issues with authentication credentials or permissions.&lt;/p&gt;
&lt;h3 id=&#34;access-denied-for-user&#34;&gt;Access denied for user&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Access denied for user &amp;lsquo;username&amp;rsquo;@&amp;lsquo;host&amp;rsquo;&amp;rdquo; or &amp;ldquo;Authentication failed&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The authentication credentials are invalid or the user doesn&amp;rsquo;t have permission to connect from the Grafana server&amp;rsquo;s host.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Verify that the username and password are correct.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check that the user exists in MySQL and is enabled.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ensure the user has permission to connect from the Grafana server&amp;rsquo;s IP address. MySQL restricts access based on the connecting host:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT user, host FROM mysql.user WHERE user = &amp;#39;your_user&amp;#39;;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If necessary, create a user that can connect from the Grafana server:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE USER &amp;#39;grafana&amp;#39;@&amp;#39;grafana_server_ip&amp;#39; IDENTIFIED BY &amp;#39;password&amp;#39;;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If using the &lt;code&gt;mysql_native_password&lt;/code&gt; authentication plugin, ensure it&amp;rsquo;s enabled on the server.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;cannot-access-database&#34;&gt;Cannot access database&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Access denied for user &amp;lsquo;username&amp;rsquo;@&amp;lsquo;host&amp;rsquo; to database &amp;lsquo;dbname&amp;rsquo;&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The authenticated user doesn&amp;rsquo;t have permission to access the specified database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Verify that the database name is correct in the data source configuration.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ensure the user has the required permissions on the database:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;GRANT SELECT ON your_database.* TO &amp;#39;grafana&amp;#39;@&amp;#39;grafana_server_ip&amp;#39;;
FLUSH PRIVILEGES;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For production environments, grant permissions only on specific tables:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;GRANT SELECT ON your_database.your_table TO &amp;#39;grafana&amp;#39;@&amp;#39;grafana_server_ip&amp;#39;;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;pam-authentication-issues&#34;&gt;PAM authentication issues&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Authentication plugin &amp;lsquo;auth_pam&amp;rsquo; cannot be loaded&amp;rdquo; or cleartext password errors&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; PAM (Pluggable Authentication Modules) authentication requires cleartext password transmission.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enable &lt;strong&gt;Allow Cleartext Passwords&lt;/strong&gt; in the data source configuration if using PAM authentication.&lt;/li&gt;
&lt;li&gt;Ensure TLS is enabled to protect password transmission when using cleartext passwords.&lt;/li&gt;
&lt;li&gt;Verify that the PAM plugin is correctly installed and configured on the MySQL server.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;query-errors&#34;&gt;Query errors&lt;/h2&gt;
&lt;p&gt;These errors occur when there are issues with query syntax or configuration.&lt;/p&gt;
&lt;h3 id=&#34;time-column-not-found-or-invalid&#34;&gt;Time column not found or invalid&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Could not find time column&amp;rdquo; or time series visualization shows no data&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query doesn&amp;rsquo;t return a properly formatted &lt;code&gt;time&lt;/code&gt; column for time series visualization.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ensure your query includes a column named &lt;code&gt;time&lt;/code&gt; when using the &lt;strong&gt;Time series&lt;/strong&gt; format.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;$__time()&lt;/code&gt; macro to convert your date column: &lt;code&gt;$__time(your_date_column)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Verify the time column is of a valid MySQL date/time type (&lt;code&gt;DATETIME&lt;/code&gt;, &lt;code&gt;TIMESTAMP&lt;/code&gt;, &lt;code&gt;DATE&lt;/code&gt;) or contains Unix epoch values.&lt;/li&gt;
&lt;li&gt;Ensure the result set is sorted by the time column using &lt;code&gt;ORDER BY&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;macro-expansion-errors&#34;&gt;Macro expansion errors&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Error parsing query&amp;rdquo; or macros appear unexpanded in the query&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana macros are being used incorrectly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify macro syntax: use &lt;code&gt;$__timeFilter(column)&lt;/code&gt; not &lt;code&gt;$_timeFilter(column)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check that the column name passed to macros exists in your table.&lt;/li&gt;
&lt;li&gt;View the expanded query by clicking &lt;strong&gt;Generated SQL&lt;/strong&gt; after running the query to debug macro expansion.&lt;/li&gt;
&lt;li&gt;Ensure backticks are used for reserved words or special characters in column names: &lt;code&gt;$__timeFilter(\&lt;/code&gt;time-column`)`.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;timezone-and-time-shift-issues&#34;&gt;Timezone and time shift issues&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Time series data appears shifted or doesn&amp;rsquo;t align with expected times.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Store timestamps in UTC in your database to avoid timezone issues.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Time macros (&lt;code&gt;$__time&lt;/code&gt;, &lt;code&gt;$__timeFilter&lt;/code&gt;, etc.) always expand to UTC values.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set the &lt;strong&gt;Session Timezone&lt;/strong&gt; in the data source configuration to match your data&amp;rsquo;s timezone, or use &lt;code&gt;&#43;00:00&lt;/code&gt; for UTC.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If your timestamps are stored in local time, convert them to UTC in your query:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  CONVERT_TZ(your_datetime_column, &amp;#39;Your/Timezone&amp;#39;, &amp;#39;UTC&amp;#39;) AS time,
  value
FROM your_table&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;query-returns-too-many-rows&#34;&gt;Query returns too many rows&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Result set too large&amp;rdquo; or browser becomes unresponsive&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query returns more data than can be efficiently processed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add time filters using &lt;code&gt;$__timeFilter(column)&lt;/code&gt; to limit data to the dashboard time range.&lt;/li&gt;
&lt;li&gt;Use aggregations (&lt;code&gt;AVG&lt;/code&gt;, &lt;code&gt;SUM&lt;/code&gt;, &lt;code&gt;COUNT&lt;/code&gt;) with &lt;code&gt;GROUP BY&lt;/code&gt; instead of returning raw rows.&lt;/li&gt;
&lt;li&gt;Add a &lt;code&gt;LIMIT&lt;/code&gt; clause to restrict results: &lt;code&gt;SELECT ... LIMIT 1000&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;$__timeGroup()&lt;/code&gt; macro to aggregate data into time intervals.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;syntax-error-in-sql-statement&#34;&gt;Syntax error in SQL statement&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;You have an error in your SQL syntax&amp;rdquo; followed by specific error details&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The SQL query contains invalid syntax.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check for missing or extra commas, parentheses, or quotes.&lt;/li&gt;
&lt;li&gt;Ensure reserved words used as identifiers are enclosed in backticks: &lt;code&gt;`table`&lt;/code&gt;, &lt;code&gt;`select`&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Verify that template variable syntax is correct: &lt;code&gt;$variable&lt;/code&gt; or &lt;code&gt;${variable}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Test the query directly in a MySQL client to isolate Grafana-specific issues.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;unknown-column-in-field-list&#34;&gt;Unknown column in field list&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Unknown column &amp;lsquo;column_name&amp;rsquo; in &amp;lsquo;field list&amp;rsquo;&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The specified column doesn&amp;rsquo;t exist in the table or is misspelled.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the column name is spelled correctly.&lt;/li&gt;
&lt;li&gt;Check that the column exists in the specified table.&lt;/li&gt;
&lt;li&gt;If the column name contains special characters or spaces, enclose it in backticks: &lt;code&gt;`column-name`&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ensure the correct database is selected if you&amp;rsquo;re referencing columns without the full table path.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;performance-issues&#34;&gt;Performance issues&lt;/h2&gt;
&lt;p&gt;These issues relate to slow queries or high resource usage.&lt;/p&gt;
&lt;h3 id=&#34;slow-query-execution&#34;&gt;Slow query execution&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Queries take a long time to execute.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Reduce the dashboard time range to limit data volume.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add indexes to columns used in &lt;code&gt;WHERE&lt;/code&gt; clauses and time filters:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE INDEX idx_time ON your_table(time_column);&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use aggregations instead of returning individual rows.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Increase the &lt;strong&gt;Min time interval&lt;/strong&gt; setting to reduce the number of data points.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Review the query execution plan using &lt;code&gt;EXPLAIN&lt;/code&gt; to identify bottlenecks:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;EXPLAIN SELECT * FROM your_table WHERE time_column &amp;gt; NOW() - INTERVAL 1 HOUR;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;connection-pool-exhaustion&#34;&gt;Connection pool exhaustion&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Too many connections&amp;rdquo; or &amp;ldquo;Connection pool exhausted&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Too many concurrent connections to the database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Increase the &lt;strong&gt;Max open&lt;/strong&gt; connection limit in the data source configuration.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enable &lt;strong&gt;Auto (max idle)&lt;/strong&gt; to automatically manage idle connections.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reduce the number of panels querying the same data source simultaneously.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check for long-running queries that might be holding connections.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Increase the &lt;code&gt;max_connections&lt;/code&gt; setting in MySQL if necessary:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SHOW VARIABLES LIKE &amp;#39;max_connections&amp;#39;;
SET GLOBAL max_connections = 200;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;query-timeout&#34;&gt;Query timeout&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Query execution was interrupted&amp;rdquo; or &amp;ldquo;Lock wait timeout exceeded&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query takes too long and exceeds the configured timeout.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Optimize the query by adding appropriate indexes.&lt;/li&gt;
&lt;li&gt;Reduce the amount of data being queried by narrowing the time range.&lt;/li&gt;
&lt;li&gt;Use aggregations to reduce the result set size.&lt;/li&gt;
&lt;li&gt;Check for table locks that might be blocking the query.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;other-common-issues&#34;&gt;Other common issues&lt;/h2&gt;
&lt;p&gt;The following issues don&amp;rsquo;t produce specific error messages but are commonly encountered.&lt;/p&gt;
&lt;h3 id=&#34;template-variable-queries-fail&#34;&gt;Template variable queries fail&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Variable queries return unexpected results or errors.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the variable query syntax is valid SQL that returns a single column.&lt;/li&gt;
&lt;li&gt;Check that the data source connection is working.&lt;/li&gt;
&lt;li&gt;Ensure the user has permission to access the tables referenced in the variable query.&lt;/li&gt;
&lt;li&gt;Test the query in the query editor before using it as a variable query.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;data-appears-incorrect-or-misaligned&#34;&gt;Data appears incorrect or misaligned&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Data formatting or type conversion issues.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use explicit column aliases to ensure consistent naming: &lt;code&gt;SELECT value AS metric&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Verify numeric columns are actually numeric types, not strings.&lt;/li&gt;
&lt;li&gt;Check for &lt;code&gt;NULL&lt;/code&gt; values that might affect aggregations.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;FILL&lt;/code&gt; option in &lt;code&gt;$__timeGroup()&lt;/code&gt; macro to handle missing data points.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;special-characters-in-database-or-table-names&#34;&gt;Special characters in database or table names&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Queries fail when tables or databases contain reserved words or special characters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enclose identifiers with special characters in backticks: &lt;code&gt;`my-database`.`my-table`&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The query editor automatically handles this for selections, but manual queries require backticks.&lt;/li&gt;
&lt;li&gt;Avoid using reserved words as identifiers when possible.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;an-unexpected-error-happened&#34;&gt;An unexpected error happened&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;An unexpected error happened&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; A general error occurred that doesn&amp;rsquo;t have a specific error message.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the Grafana server logs for more details about the error.&lt;/li&gt;
&lt;li&gt;Verify all data source configuration settings are correct.&lt;/li&gt;
&lt;li&gt;Test the connection using the &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; button.&lt;/li&gt;
&lt;li&gt;Ensure the MySQL server is accessible and responding to queries.&lt;/li&gt;
&lt;li&gt;For Grafana Cloud customers, contact support for assistance.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;get-additional-help&#34;&gt;Get additional help&lt;/h2&gt;
&lt;p&gt;If you continue to experience issues after following this troubleshooting guide:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the &lt;a href=&#34;https://community.grafana.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana community forums&lt;/a&gt; for similar issues.&lt;/li&gt;
&lt;li&gt;Review the &lt;a href=&#34;https://github.com/grafana/grafana/issues&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana GitHub issues&lt;/a&gt; for known bugs.&lt;/li&gt;
&lt;li&gt;Enable debug logging in Grafana to capture detailed error information.&lt;/li&gt;
&lt;li&gt;Check MySQL error logs for additional details.&lt;/li&gt;
&lt;li&gt;Contact Grafana Support if you&amp;rsquo;re an Enterprise or Cloud customer.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When reporting issues, include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Grafana version&lt;/li&gt;
&lt;li&gt;MySQL version&lt;/li&gt;
&lt;li&gt;Error messages (redact sensitive information)&lt;/li&gt;
&lt;li&gt;Steps to reproduce&lt;/li&gt;
&lt;li&gt;Relevant query examples (redact sensitive data)&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="troubleshoot-mysql-data-source-issues">Troubleshoot MySQL data source issues&lt;/h1>
&lt;p>This document provides solutions to common issues you may encounter when configuring or using the MySQL data source in Grafana.&lt;/p></description></item></channel></rss>