docs/sources/datasources/mysql/configure/_index.md
This document provides instructions for configuring the MySQL data source and explains available configuration options. For general information on managing data sources refer to Data source management.
Before configuring the MySQL data source, ensure you have the following:
Grafana permissions: You must have the Organization administrator role to configure data sources. Organization administrators can also configure the data source via YAML with the Grafana provisioning system.
A running MySQL instance: MySQL 5.7 or newer, MariaDB 10.2 or newer, or a compatible MySQL-based database such as Percona Server.
Network access: Grafana must be able to reach your MySQL server. The default port is 3306.
Authentication credentials: A MySQL user with at least SELECT permissions on the databases and tables you want to query.
Security certificates: If using encrypted connections, gather any necessary TLS/SSL certificates.
{{< admonition type="note" >}} Grafana ships with a built-in MySQL data source plugin. No additional installation is required. {{< /admonition >}}
{{< admonition type="tip" >}} Grafana Cloud users: If your MySQL server is in a private network, you can configure Private data source connect to establish connectivity. {{< /admonition >}}
When adding a data source, ensure the database user you specify has only SELECT permissions on the relevant database and tables. Grafana doesn't validate the safety of queries, which means they can include potentially harmful SQL statements, such as USE otherdb; or DROP TABLE user;, which could get executed.
To minimize this risk, Grafana strongly recommends creating a dedicated MySQL user with restricted permissions:
CREATE USER 'grafanaReader' IDENTIFIED BY 'password';
GRANT SELECT ON mydatabase.mytable TO 'grafanaReader';
Use wildcards (*) in place of a database or table if you want to grant access to more databases and tables.
To add the MySQL data source complete the following steps:
MySQL in the search bar.You are taken to the Settings tab where you will configure the data source.
Following is a list of MySQL configuration options:
mysql-assets-1, mysqldb1.Connection:
3306 port will be used.Authentication:
The following are additional MySQL settings.
MySQL options:
Europe/Berlin or +02:00. Required if the timezone of the database (or the host of the database) is set to something other than UTC. Set this to +00:00 so Grafana can handle times properly. Set the value used in the session with SET time_zone='...'. If you leave this field empty, the timezone will not be updated. For more information, refer to MySQL Server Time Zone Support.$__interval and $__interval_ms variables. Grafana recommends aligning this setting with the data write frequency. For example, set it to 1m if your data is written every minute. Refer to Min time interval for format examples.Connection limits:
100.100.true.14400, or 4 hours.Private data source connect:
Private data source connect - Only for Grafana Cloud users. 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 Private data source connect (PDC).
Click Manage private data source connect to be taken to your PDC connection page, where you’ll find your PDC configuration details.
Once you have added your MySQL connection settings, click Save & test to test and save the data source connection.
The Min time interval setting defines a lower limit for the $__interval and $__interval_ms variables.
This value must be formatted as a number followed by a valid time identifier:
| Identifier | Description |
|---|---|
y | year |
M | month |
w | week |
d | day |
h | hour |
m | minute |
s | second |
ms | millisecond |
You can override this setting in a dashboard panel under its data source options.
You can define and configure the data source in YAML files as part of Grafana's provisioning system. For more information about provisioning, and available configuration options, refer to Provision Grafana.
Basic provisioning:
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}
Using TLS verification:
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}
Use TLS and skip certificate verification:
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}
You can configure the MySQL data source using Terraform with the Grafana Terraform provider.
For more information about provisioning resources with Terraform, refer to the Grafana as code using Terraform documentation.
The following example creates a basic MySQL data source:
resource "grafana_data_source" "mysql" {
name = "MySQL"
type = "mysql"
url = "localhost:3306"
user = "grafana"
json_data_encoded = jsonencode({
database = "grafana"
maxOpenConns = 100
maxIdleConns = 100
maxIdleConnsAuto = true
connMaxLifetime = 14400
})
secure_json_data_encoded = jsonencode({
password = "password"
})
}
For all available configuration options, refer to the Grafana provider data source resource documentation.
After configuring your MySQL data source, you can: