mirror of
https://github.com/grafana/grafana.git
synced 2026-01-15 05:35:41 +00:00
Compare commits
7 Commits
ash/react-
...
docs/updat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6d18a279f | ||
|
|
e15a7e4286 | ||
|
|
c830948255 | ||
|
|
6f1d840222 | ||
|
|
179a9f7f02 | ||
|
|
628b6174e9 | ||
|
|
bf727ef41a |
@@ -322,7 +322,7 @@ If you continue to experience issues after following this troubleshooting guide:
|
||||
1. Review the [Grafana GitHub issues](https://github.com/grafana/grafana/issues) for known bugs.
|
||||
1. Enable debug logging in Grafana to capture detailed error information.
|
||||
1. Check SQL Server logs for additional error details.
|
||||
1. Contact Grafana Support if you're an Enterprise or Cloud customer.
|
||||
1. Contact [Grafana Support](https://grafana.com/contact/) if you're an Enterprise or Cloud customer.
|
||||
|
||||
When reporting issues, include:
|
||||
|
||||
|
||||
@@ -17,52 +17,145 @@ menuTitle: MySQL
|
||||
title: MySQL data source
|
||||
weight: 1000
|
||||
refs:
|
||||
annotate-visualizations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/build-dashboards/annotate-visualizations/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/dashboards/build-dashboards/annotate-visualizations/
|
||||
configure-mysql-data-source:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/configuration/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/configure/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/configuration/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/configure/
|
||||
mysql-query-editor:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/query-editor/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/query-editor/
|
||||
alerting:
|
||||
troubleshoot-mysql:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/alerting/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/troubleshooting/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/alerting-and-irm/alerting/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/troubleshooting/
|
||||
mysql-template-variables:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/template-variables/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/template-variables/
|
||||
mysql-alerting:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/alerting/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/alerting/
|
||||
mysql-annotations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/annotations/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/annotations/
|
||||
transformations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/panels-visualizations/query-transform-data/transform-data/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/panels-visualizations/query-transform-data/transform-data/
|
||||
visualizations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/panels-visualizations/visualizations/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/panels-visualizations/visualizations/
|
||||
variables:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/dashboards/variables/
|
||||
query-caching:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/administration/data-source-management/#query-and-resource-caching
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/administration/data-source-management/#query-and-resource-caching
|
||||
postgres:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/postgres/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/postgres/
|
||||
mssql:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mssql/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mssql/
|
||||
---
|
||||
|
||||
# MySQL data source
|
||||
|
||||
Grafana ships with a built-in MySQL data source plugin that allows you to query and visualize data from a MySQL-compatible database like [MariaDB](https://mariadb.org/) or [Percona Server](https://www.percona.com/). You don't need to install a plugin in order to add the MySQL data source to your Grafana instance.
|
||||
Grafana ships with built-in support for MySQL.
|
||||
You can query and visualize data from MySQL-compatible databases like [MariaDB](https://mariadb.org/) or [Percona Server](https://www.percona.com/).
|
||||
|
||||
Grafana offers several configuration options for this data source as well as a visual and code-based query editor.
|
||||
Use this data source to create dashboards, explore SQL data, and monitor MySQL-based workloads in real time.
|
||||
|
||||
## Get started with the MySQL data source
|
||||
{{< docs/play title="MySQL Overview" url="https://play.grafana.org/d/edyh1ib7db6rkb/mysql-overview" >}}
|
||||
|
||||
The following documents will help you get started with the MySQL data source in Grafana:
|
||||
## Supported databases
|
||||
|
||||
This data source supports the following MySQL-compatible databases:
|
||||
|
||||
- MySQL 5.7 and newer
|
||||
- MySQL 8.0 and newer
|
||||
- MariaDB 10.2 and newer
|
||||
- Percona Server 5.7 and newer
|
||||
- Amazon Aurora MySQL
|
||||
- Azure Database for MySQL
|
||||
- Google Cloud SQL for MySQL
|
||||
|
||||
Grafana recommends using the latest available version for your database for optimal compatibility.
|
||||
|
||||
## Key capabilities
|
||||
|
||||
The MySQL data source supports:
|
||||
|
||||
- **Time series queries:** Visualize metrics over time using built-in time grouping macros.
|
||||
- **Table queries:** Display query results in table format for any valid SQL query.
|
||||
- **Template variables:** Create dynamic dashboards with variable-driven queries.
|
||||
- **Annotations:** Overlay events from MySQL on your dashboard graphs.
|
||||
- **Alerting:** Create alerts based on MySQL query results.
|
||||
- **Macros:** Simplify queries with built-in macros for time filtering and grouping.
|
||||
|
||||
## Get started
|
||||
|
||||
The following documentation helps you get started with the MySQL data source:
|
||||
|
||||
- [Configure the MySQL data source](ref:configure-mysql-data-source)
|
||||
- [MySQL query editor](ref:mysql-query-editor)
|
||||
- [MySQL template variables](ref:mysql-template-variables)
|
||||
- [MySQL annotations](ref:mysql-annotations)
|
||||
- [MySQL alerting](ref:mysql-alerting)
|
||||
- [Troubleshoot MySQL data source issues](ref:troubleshoot-mysql)
|
||||
|
||||
Once you have configured the data source you can:
|
||||
## Additional resources
|
||||
|
||||
- Add [annotations](ref:annotate-visualizations)
|
||||
- Set up [alerting](ref:alerting)
|
||||
- Add [transformations](ref:transformations)
|
||||
After configuring the MySQL data source, you can also:
|
||||
|
||||
View a MySQL overview on Grafana Play:
|
||||
- Create a wide variety of [visualizations](ref:visualizations).
|
||||
- Configure and use [templates and variables](ref:variables).
|
||||
- Add [transformations](ref:transformations).
|
||||
- Optimize performance with [query caching](ref:query-caching).
|
||||
|
||||
{{< docs/play title="MySQL Overview" url="https://play.grafana.org/d/edyh1ib7db6rkb/mysql-overview" >}}
|
||||
## Pre-configured dashboards
|
||||
|
||||
If you want to monitor your MySQL server's performance metrics (connections, queries, replication, and more), Grafana provides pre-configured dashboards through the MySQL integration:
|
||||
|
||||
- **MySQL Overview** - Key performance metrics for your MySQL server.
|
||||
- **MySQL Logs** - Log analysis for troubleshooting.
|
||||
|
||||
The MySQL integration uses the Prometheus MySQL Exporter to collect server metrics and includes 15 pre-configured alert rules.
|
||||
|
||||
To use these dashboards:
|
||||
|
||||
1. In Grafana Cloud, navigate to **Connections** > **Add new connection**.
|
||||
1. Search for **MySQL** and select the MySQL integration.
|
||||
1. Follow the setup instructions to install the MySQL Exporter.
|
||||
1. Import the pre-configured dashboards from the integration page.
|
||||
|
||||
For more MySQL dashboards, browse the [Grafana dashboard catalog](https://grafana.com/grafana/dashboards/?search=mysql).
|
||||
|
||||
{{< admonition type="note" >}}
|
||||
The MySQL integration monitors your MySQL _server_ using Prometheus metrics. The MySQL _data source_ documented here queries data stored _in_ MySQL tables. These are complementary features for different use cases.
|
||||
{{< /admonition >}}
|
||||
|
||||
## Related data sources
|
||||
|
||||
- [PostgreSQL](ref:postgres) - For PostgreSQL databases.
|
||||
- [Microsoft SQL Server](ref:mssql) - For Microsoft SQL Server and Azure SQL databases.
|
||||
|
||||
188
docs/sources/datasources/mysql/alerting/index.md
Normal file
188
docs/sources/datasources/mysql/alerting/index.md
Normal file
@@ -0,0 +1,188 @@
|
||||
---
|
||||
description: Using Grafana Alerting with the MySQL data source
|
||||
keywords:
|
||||
- grafana
|
||||
- mysql
|
||||
- alerting
|
||||
- alerts
|
||||
labels:
|
||||
products:
|
||||
- cloud
|
||||
- enterprise
|
||||
- oss
|
||||
menuTitle: Alerting
|
||||
title: MySQL alerting
|
||||
weight: 350
|
||||
refs:
|
||||
alerting:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/alerting/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/alerting-and-irm/alerting/
|
||||
create-alert-rule:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/alerting/alerting-rules/create-grafana-managed-rule/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/alerting-and-irm/alerting/alerting-rules/create-grafana-managed-rule/
|
||||
mysql-query-editor:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/query-editor/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/query-editor/
|
||||
---
|
||||
|
||||
# MySQL alerting
|
||||
|
||||
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.
|
||||
|
||||
For general information about Grafana Alerting, refer to [Grafana Alerting](ref:alerting).
|
||||
|
||||
## Before you begin
|
||||
|
||||
Before creating alerts with MySQL, ensure you have:
|
||||
|
||||
- A MySQL data source configured in Grafana.
|
||||
- Appropriate permissions to create alert rules.
|
||||
- Understanding of the metrics you want to monitor.
|
||||
|
||||
## Supported query types
|
||||
|
||||
MySQL alerting works with **time series queries** that return numeric data over time. Table formatted queries are not supported in alert rule conditions.
|
||||
|
||||
To create a valid alert query:
|
||||
|
||||
- Include a `time` column that returns a SQL datetime or UNIX epoch timestamp
|
||||
- Return numeric values for the metrics you want to alert on
|
||||
- Sort results by the time column
|
||||
|
||||
For more information on writing time series queries, refer to [MySQL query editor](ref:mysql-query-editor).
|
||||
|
||||
### Query format requirements
|
||||
|
||||
| Query format | Alerting support | Notes |
|
||||
| ------------ | ---------------- | ---------------------------------------- |
|
||||
| Time series | Yes | Required for alerting |
|
||||
| Table | No | Convert to time series format for alerts |
|
||||
|
||||
## Create an alert rule
|
||||
|
||||
To create an alert rule using MySQL:
|
||||
|
||||
1. Navigate to **Alerting** > **Alert rules**.
|
||||
1. Click **New alert rule**.
|
||||
1. Enter a name for the alert rule.
|
||||
1. Select your **MySQL** data source.
|
||||
1. Build your query using the query editor:
|
||||
- Set the **Format** to **Time series**
|
||||
- Include a time column using the `$__time()` or `$__timeGroup()` macro
|
||||
- Add numeric columns for the values to monitor
|
||||
- Use `$__timeFilter()` to filter data by the dashboard time range
|
||||
1. Configure the alert condition (for example, when the average is above a threshold).
|
||||
1. Set the evaluation interval and pending period.
|
||||
1. Configure notifications and labels.
|
||||
1. Click **Save rule**.
|
||||
|
||||
For detailed instructions, refer to [Create a Grafana-managed alert rule](ref:create-alert-rule).
|
||||
|
||||
## Example alert queries
|
||||
|
||||
The following examples show common alerting scenarios with MySQL.
|
||||
|
||||
### Alert on high error count
|
||||
|
||||
Monitor the number of errors over time:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
$__timeGroup(created_at, '1m') AS time,
|
||||
COUNT(*) AS error_count
|
||||
FROM error_logs
|
||||
WHERE $__timeFilter(created_at)
|
||||
AND level = 'error'
|
||||
GROUP BY time
|
||||
ORDER BY time
|
||||
```
|
||||
|
||||
**Condition:** When error_count is above 100.
|
||||
|
||||
### Alert on average response time
|
||||
|
||||
Monitor API response times:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
$__timeGroup(request_time, '5m') AS time,
|
||||
AVG(response_time_ms) AS avg_response_time
|
||||
FROM api_requests
|
||||
WHERE $__timeFilter(request_time)
|
||||
GROUP BY time
|
||||
ORDER BY time
|
||||
```
|
||||
|
||||
**Condition:** When avg_response_time is above 500 (milliseconds).
|
||||
|
||||
### Alert on low order volume
|
||||
|
||||
Detect drops in order activity:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
$__timeGroup(order_date, '1h') AS time,
|
||||
COUNT(*) AS order_count
|
||||
FROM orders
|
||||
WHERE $__timeFilter(order_date)
|
||||
GROUP BY time
|
||||
ORDER BY time
|
||||
```
|
||||
|
||||
**Condition:** When order_count is below 10.
|
||||
|
||||
### Alert on disk usage percentage
|
||||
|
||||
Monitor database storage metrics:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
$__timeGroup(recorded_at, '5m') AS time,
|
||||
AVG(disk_used_percent) AS disk_usage
|
||||
FROM system_metrics
|
||||
WHERE $__timeFilter(recorded_at)
|
||||
AND metric_type = 'disk'
|
||||
GROUP BY time
|
||||
ORDER BY time
|
||||
```
|
||||
|
||||
**Condition:** When disk_usage is above 85.
|
||||
|
||||
## Limitations
|
||||
|
||||
When using MySQL with Grafana Alerting, be aware of the following limitations:
|
||||
|
||||
### Template variables not supported
|
||||
|
||||
Alert queries cannot contain template variables. Grafana evaluates alert rules on the backend without dashboard context, so variables like `$hostname` or `$environment` won't be resolved.
|
||||
|
||||
If your dashboard query uses template variables, create a separate query for alerting with hard coded values.
|
||||
|
||||
### Table format not supported
|
||||
|
||||
Queries using the **Table** format cannot be used for alerting. Set the query format to **Time series** and ensure your query returns a time column.
|
||||
|
||||
### Query timeout
|
||||
|
||||
Complex queries with large datasets may timeout during alert evaluation. Optimize queries for alerting by:
|
||||
|
||||
- Adding appropriate `WHERE` clauses to limit data
|
||||
- Using indexes on time and filter columns
|
||||
- Reducing the time range evaluated
|
||||
|
||||
## Best practices
|
||||
|
||||
Follow these best practices when creating MySQL alerts:
|
||||
|
||||
- **Use time series format:** Always set the query format to Time series for alert queries.
|
||||
- **Include time filters:** Use the `$__timeFilter()` macro to limit data to the evaluation window.
|
||||
- **Optimize queries:** Add indexes on columns used in `WHERE` clauses and `GROUP BY`.
|
||||
- **Test queries first:** Verify your query returns expected results in Explore before creating an alert.
|
||||
- **Set realistic thresholds:** Base alert thresholds on historical data patterns.
|
||||
- **Use meaningful names:** Give alert rules descriptive names that indicate what they monitor.
|
||||
163
docs/sources/datasources/mysql/annotations/index.md
Normal file
163
docs/sources/datasources/mysql/annotations/index.md
Normal file
@@ -0,0 +1,163 @@
|
||||
---
|
||||
description: Using annotations with MySQL in Grafana
|
||||
keywords:
|
||||
- grafana
|
||||
- mysql
|
||||
- annotations
|
||||
- events
|
||||
labels:
|
||||
products:
|
||||
- cloud
|
||||
- enterprise
|
||||
- oss
|
||||
menuTitle: Annotations
|
||||
title: MySQL annotations
|
||||
weight: 340
|
||||
refs:
|
||||
annotate-visualizations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/build-dashboards/annotate-visualizations/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/build-dashboards/annotate-visualizations/
|
||||
---
|
||||
|
||||
# MySQL annotations
|
||||
|
||||
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.
|
||||
|
||||
For general information about annotations, refer to [Annotate visualizations](ref:annotate-visualizations).
|
||||
|
||||
## Before you begin
|
||||
|
||||
Before creating MySQL annotations, ensure you have:
|
||||
|
||||
- A MySQL data source configured in Grafana.
|
||||
- Tables containing event data with timestamp fields.
|
||||
- Read access to the tables containing your events.
|
||||
|
||||
## Create an annotation query
|
||||
|
||||
To add a MySQL annotation to your dashboard:
|
||||
|
||||
1. Navigate to your dashboard and click **Dashboard settings** (gear icon).
|
||||
1. Select **Annotations** in the left menu.
|
||||
1. Click **Add annotation query**.
|
||||
1. Enter a **Name** for the annotation.
|
||||
1. Select your **MySQL** data source from the **Data source** drop-down.
|
||||
1. Write a SQL query that returns the required columns.
|
||||
1. Click **Save dashboard**.
|
||||
|
||||
## Query columns
|
||||
|
||||
Your annotation query must return a `time` column and can optionally include `timeend`, `text`, and `tags` columns.
|
||||
|
||||
| Column | Required | Description |
|
||||
| --------- | -------- | --------------------------------------------------------------------------------------------- |
|
||||
| `time` | Yes | The timestamp for the annotation. Can be a SQL datetime or UNIX epoch value. |
|
||||
| `timeend` | No | The end timestamp for range annotations. Creates a shaded region instead of a vertical line. |
|
||||
| `text` | No | The annotation description displayed when you hover over the annotation. |
|
||||
| `tags` | No | Tags for the annotation as a comma-separated string. Helps categorize and filter annotations. |
|
||||
|
||||
## Example queries
|
||||
|
||||
The following examples show common annotation query patterns.
|
||||
|
||||
### Basic annotation with epoch time
|
||||
|
||||
Display events using UNIX epoch timestamps:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
epoch_time as time,
|
||||
description as text,
|
||||
CONCAT(tag1, ',', tag2) as tags
|
||||
FROM events
|
||||
WHERE $__unixEpochFilter(epoch_time)
|
||||
```
|
||||
|
||||
### Annotation with a single tag
|
||||
|
||||
Display events with a single tag value:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
epoch_time as time,
|
||||
message as text,
|
||||
category as tags
|
||||
FROM event_log
|
||||
WHERE $__unixEpochFilter(epoch_time)
|
||||
```
|
||||
|
||||
### Range annotation with start and end time
|
||||
|
||||
Display events with duration as shaded regions:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
start_time as time,
|
||||
end_time as timeend,
|
||||
description as text,
|
||||
CONCAT(type, ',', severity) as tags
|
||||
FROM incidents
|
||||
WHERE $__unixEpochFilter(start_time)
|
||||
```
|
||||
|
||||
### Annotation with native SQL datetime
|
||||
|
||||
Display events using native MySQL datetime columns:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
event_date as time,
|
||||
message as text,
|
||||
CONCAT(category, ',', priority) as tags
|
||||
FROM system_events
|
||||
WHERE $__timeFilter(event_date)
|
||||
```
|
||||
|
||||
### Deployment annotations
|
||||
|
||||
Display deployment events:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
deployed_at as time,
|
||||
CONCAT('Deployed ', version, ' to ', environment) as text,
|
||||
environment as tags
|
||||
FROM deployments
|
||||
WHERE $__timeFilter(deployed_at)
|
||||
```
|
||||
|
||||
### Maintenance window annotations
|
||||
|
||||
Display maintenance windows as range annotations:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
start_time as time,
|
||||
end_time as timeend,
|
||||
CONCAT('Maintenance: ', description) as text,
|
||||
'maintenance' as tags
|
||||
FROM maintenance_windows
|
||||
WHERE $__timeFilter(start_time)
|
||||
```
|
||||
|
||||
## Macros
|
||||
|
||||
Use these macros in your annotation queries to filter by the dashboard time range:
|
||||
|
||||
| Macro | Description |
|
||||
| ---------------------------- | ---------------------------------------------------------------- |
|
||||
| `$__timeFilter(column)` | Filters by time range using a native SQL datetime column. |
|
||||
| `$__unixEpochFilter(column)` | Filters by time range using a column with UNIX epoch timestamps. |
|
||||
|
||||
## Best practices
|
||||
|
||||
Follow these best practices when creating MySQL annotations:
|
||||
|
||||
- **Use time filters:** Always include `$__timeFilter()` or `$__unixEpochFilter()` to limit results to the dashboard time range.
|
||||
- **Keep queries efficient:** Add indexes on time columns and filter columns to improve query performance.
|
||||
- **Use meaningful text:** Include descriptive information in the `text` column to make annotations useful.
|
||||
- **Organize with tags:** Use consistent tag values to categorize annotations and enable filtering.
|
||||
- **Test queries first:** Verify your query returns expected results in Explore before adding it as an annotation.
|
||||
@@ -1,4 +1,6 @@
|
||||
---
|
||||
aliases:
|
||||
- ../configuration/
|
||||
description: This document provides instructions for configuring the MySQL data source and explains available configuration options.
|
||||
keywords:
|
||||
- grafana
|
||||
@@ -10,7 +12,7 @@ labels:
|
||||
- cloud
|
||||
- enterprise
|
||||
- oss
|
||||
menuTitle: Configure the MySQL data source
|
||||
menuTitle: Configure
|
||||
title: Configure the MySQL data source
|
||||
weight: 10
|
||||
refs:
|
||||
@@ -34,6 +36,41 @@ refs:
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/administration/data-source-management/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/administration/data-source-management/
|
||||
mysql-query-editor:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/query-editor/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/query-editor/
|
||||
annotate-visualizations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/build-dashboards/annotate-visualizations/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/dashboards/build-dashboards/annotate-visualizations/
|
||||
alerting:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/alerting/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/alerting-and-irm/alerting/
|
||||
mysql-alerting:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/alerting/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/alerting/
|
||||
mysql-annotations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/annotations/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/annotations/
|
||||
mysql-troubleshoot:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/troubleshooting/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/troubleshooting/
|
||||
mysql-template-variables:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/template-variables/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/template-variables/
|
||||
---
|
||||
|
||||
# Configure the MySQL data source
|
||||
@@ -42,24 +79,35 @@ This document provides instructions for configuring the MySQL data source and ex
|
||||
|
||||
## Before you begin
|
||||
|
||||
You must have the `Organization administrator` role in order to configure the MySQL data source.
|
||||
Administrators can also [configure the data source via YAML](#provision-the-data-source) with Grafana's provisioning system.
|
||||
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](#provision-the-data-source) 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 the MySQL data source by default, so no additional installation is required.
|
||||
Grafana ships with a built-in MySQL data source plugin. No additional installation is required.
|
||||
{{< /admonition >}}
|
||||
|
||||
{{< admonition type="caution" >}}
|
||||
When adding a data source, ensure the database user you specify has only `SELECT` permissions on the relevant database and tables. Grafana does not 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.
|
||||
{{< admonition type="tip" >}}
|
||||
**Grafana Cloud users:** If your MySQL server is in a private network, you can configure [Private data source connect](https://grafana.com/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/) to establish connectivity.
|
||||
{{< /admonition >}}
|
||||
|
||||
Example:
|
||||
### Database user permissions
|
||||
|
||||
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:
|
||||
|
||||
```sql
|
||||
CREATE USER 'grafanaReader' IDENTIFIED BY 'password';
|
||||
GRANT SELECT ON mydatabase.mytable TO 'grafanaReader';
|
||||
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.
|
||||
@@ -213,3 +261,46 @@ datasources:
|
||||
tlsClientCert: ${GRAFANA_TLS_CLIENT_CERT}
|
||||
tlsCACert: ${GRAFANA_TLS_CA_CERT}
|
||||
```
|
||||
|
||||
## Configure with Terraform
|
||||
|
||||
You can configure the MySQL data source using [Terraform](https://www.terraform.io/) with the [Grafana Terraform provider](https://registry.terraform.io/providers/grafana/grafana/latest/docs).
|
||||
|
||||
For more information about provisioning resources with Terraform, refer to the [Grafana as code using Terraform](https://grafana.com/docs/grafana-cloud/developer-resources/infrastructure-as-code/terraform/) documentation.
|
||||
|
||||
### Terraform example
|
||||
|
||||
The following example creates a basic MySQL data source:
|
||||
|
||||
```hcl
|
||||
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](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/data_source).
|
||||
|
||||
## Next steps
|
||||
|
||||
After configuring your MySQL data source, you can:
|
||||
|
||||
- [Write queries](ref:mysql-query-editor) using the query editor to explore and visualize your data.
|
||||
- [Use template variables](ref:mysql-template-variables) to create dynamic, reusable dashboards.
|
||||
- [Add annotations](ref:mysql-annotations) to overlay MySQL events on your graphs.
|
||||
- [Set up alerting](ref:mysql-alerting) to create alert rules based on your MySQL data.
|
||||
- [Troubleshoot issues](ref:mysql-troubleshoot) if you encounter problems with your data source.
|
||||
@@ -9,7 +9,7 @@ labels:
|
||||
- cloud
|
||||
- enterprise
|
||||
- oss
|
||||
menuTitle: MySQL query editor
|
||||
menuTitle: Query editor
|
||||
title: MySQL query editor
|
||||
weight: 30
|
||||
refs:
|
||||
@@ -61,6 +61,21 @@ refs:
|
||||
configure-standard-options:
|
||||
- pattern: /docs/grafana/
|
||||
- destination: /docs/grafana/<GRAFANA_VERSION>/panels-visualizations/configure-standard-options/
|
||||
mysql-template-variables:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/template-variables/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/template-variables/
|
||||
mysql-alerting:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/alerting/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/alerting/
|
||||
mysql-annotations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/annotations/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/annotations/
|
||||
---
|
||||
|
||||
# MySQL query editor
|
||||
@@ -305,171 +320,20 @@ Table panel result:
|
||||
|
||||
The query returns multiple columns representing minimum and maximum values within the defined range.
|
||||
|
||||
## Templating
|
||||
## Template variables
|
||||
|
||||
Instead of hardcoding 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. These drop-downs make it easy to change the data being displayed in your dashboard.
|
||||
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.
|
||||
|
||||
Refer to [Templates](ref:variables) for an introduction to creating template variables as well as the different types.
|
||||
|
||||
### Query variable
|
||||
|
||||
If you add a `Query` template variable you can write a MySQL query to retrieve items such as measurement names, key names, or key values, which will be displayed in the drop-down menu.
|
||||
|
||||
For example, you can use a variable to retrieve all the values from the `hostname` column in a table by creating the following query in the templating variable _Query_ setting.
|
||||
|
||||
```sql
|
||||
SELECT hostname FROM my_host
|
||||
```
|
||||
|
||||
A query can return multiple columns, and Grafana will automatically generate a list based on the query results. For example, the following query returns a list with values from `hostname` and `hostname2`.
|
||||
|
||||
```sql
|
||||
SELECT my_host.hostname, my_other_host.hostname2 FROM my_host JOIN my_other_host ON my_host.city = my_other_host.city
|
||||
```
|
||||
|
||||
To use time range dependent macros like `$__timeFilter(column)` in your query,you must set the template variable's refresh mode to _On Time Range Change_.
|
||||
|
||||
```sql
|
||||
SELECT event_name FROM event_log WHERE $__timeFilter(time_column)
|
||||
```
|
||||
|
||||
Another option is a query that can create a key/value variable. The query should return two columns that are named `__text` and `__value`. The `__text` column must contain unique values (if not, only the first value is used). This allows the drop-down options to display a text-friendly name as the text while using an ID as the value. For example, a query could use `hostname` as the text and `id` as the value:
|
||||
|
||||
```sql
|
||||
SELECT hostname AS __text, id AS __value FROM my_host
|
||||
```
|
||||
|
||||
You can also create nested variables. For example, if you have a variable named `region`, you can configure the `hosts` variable to display only the hosts within the currently selected region as shown in the following example. If `region` is a multi-value variable, use the `IN` operator instead of `=` to match multiple values.
|
||||
|
||||
```sql
|
||||
SELECT hostname FROM my_host WHERE region IN($region)
|
||||
```
|
||||
|
||||
#### Use `__searchFilter` to filter results in a query variable
|
||||
|
||||
Using `__searchFilter` in the query field allows the query results to be filtered based on the user’s input in the drop-down selection box. If you do not enter anything, the default value for `__searchFilter` is %
|
||||
|
||||
Note that you must enclose the `__searchFilter` expression in quotes as Grafana does not add them automatically.
|
||||
|
||||
The following example demonstrates how to use `__searchFilter` in the query field to enable real-time searching for `hostname` as the user type in the drop-down selection box.
|
||||
|
||||
```sql
|
||||
SELECT hostname FROM my_host WHERE hostname LIKE '$__searchFilter'
|
||||
```
|
||||
|
||||
### Using variables in queries
|
||||
|
||||
Template variable values are only quoted when the template variable is a `multi-value`.
|
||||
|
||||
If the variable is a multi-value variable, use the `IN` comparison operator instead of `=` to match against multiple values.
|
||||
|
||||
You can use two different syntaxes:
|
||||
|
||||
`$<varname>` Example with a template variable named `hostname`:
|
||||
|
||||
```sql
|
||||
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
|
||||
```
|
||||
|
||||
`[[varname]]` Example with a template variable named `hostname`:
|
||||
|
||||
```sql
|
||||
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
|
||||
```
|
||||
|
||||
#### Disabling quoting for multi-value variables
|
||||
|
||||
Grafana automatically creates a quoted, comma-separated string for multi-value variables. For example: if `server01` and `server02` are selected then it will be formatted as: `'server01', 'server02'`. To disable quoting, use the csv formatting option for variables:
|
||||
|
||||
Grafana automatically formats multi-value variables as a quoted, comma-separated string. For example, if `server01` and `server02` are selected, they are formatted as `'server01'`, `'server02'`. To remove the quotes, enable the CSV formatting option for the variables.
|
||||
|
||||
`${servers:csv}`
|
||||
|
||||
Read more about variable formatting options in the [Variables](ref:variable-syntax-advanced-variable-format-options) documentation.
|
||||
For detailed information on using template variables with MySQL, refer to [MySQL template variables](ref:mysql-template-variables).
|
||||
|
||||
## Annotations
|
||||
|
||||
[Annotations](ref:annotate-visualizations) allow you to overlay rich event information on top of graphs. You add annotation queries via the **Dashboard settings > Annotations view**.
|
||||
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.
|
||||
|
||||
**Example query using a`time` column with epoch values:**
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
epoch_time as time,
|
||||
metric1 as text,
|
||||
CONCAT(tag1, ',', tag2) as tags
|
||||
FROM
|
||||
public.test_data
|
||||
WHERE
|
||||
$__unixEpochFilter(epoch_time)
|
||||
```
|
||||
|
||||
You may use one or more tags to show them as annotations in a common-separate string.
|
||||
|
||||
**Example query using a `time` column with epoch values for a single tag:**
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
epoch_time as time,
|
||||
metric1 as text,
|
||||
tag1 as tag
|
||||
FROM
|
||||
my_data
|
||||
WHERE
|
||||
$__unixEpochFilter(epoch_time)
|
||||
```
|
||||
|
||||
**Example region query using `time` and `timeend` columns with epoch values:**
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
epoch_time as time,
|
||||
epoch_timeend as timeend,
|
||||
metric1 as text,
|
||||
CONCAT(tag1, ',', tag2) as tags
|
||||
FROM
|
||||
public.test_data
|
||||
WHERE
|
||||
$__unixEpochFilter(epoch_time)
|
||||
```
|
||||
|
||||
**Example query using a `time` column with a native SQL date/time data type:**
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
native_date_time as time,
|
||||
metric1 as text,
|
||||
CONCAT(tag1, ',', tag2) as tags
|
||||
FROM
|
||||
public.test_data
|
||||
WHERE
|
||||
$__timeFilter(native_date_time)
|
||||
```
|
||||
|
||||
| Name | Description |
|
||||
| --------- | --------------------------------------------------------------------------------------------------------------------- |
|
||||
| `time` | The name of the date/time field, which can be a column with a native SQL date/time data type or epoch value. |
|
||||
| `timeend` | Optional name of the end date/time field, which can be a column with a native SQL date/time data type or epoch value. |
|
||||
| `text` | Event description field. |
|
||||
| `tags` | Optional field name to use for event tags as a comma separated string. |
|
||||
For detailed information on creating annotations with MySQL, refer to [MySQL annotations](ref:mysql-annotations).
|
||||
|
||||
## Alerting
|
||||
|
||||
Use time series queries to create alerts. Table formatted queries aren't yet supported in alert rule conditions.
|
||||
You can use time series queries to create Grafana-managed alert rules. Table formatted queries are not supported in alert rule conditions.
|
||||
|
||||
For more information regarding alerting refer to the following:
|
||||
|
||||
- [Alert rules](ref:alert-rules)
|
||||
- [Template annotations and labels](ref:template-annotations-and-labels)
|
||||
For detailed information on creating alerts with MySQL, refer to [MySQL alerting](ref:mysql-alerting).
|
||||
|
||||
146
docs/sources/datasources/mysql/template-variables/index.md
Normal file
146
docs/sources/datasources/mysql/template-variables/index.md
Normal file
@@ -0,0 +1,146 @@
|
||||
---
|
||||
description: Using template variables with MySQL in Grafana
|
||||
keywords:
|
||||
- grafana
|
||||
- mysql
|
||||
- templates
|
||||
- variables
|
||||
- queries
|
||||
labels:
|
||||
products:
|
||||
- cloud
|
||||
- enterprise
|
||||
- oss
|
||||
menuTitle: Template variables
|
||||
title: MySQL template variables
|
||||
weight: 300
|
||||
refs:
|
||||
variables:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/
|
||||
variable-syntax-advanced-variable-format-options:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/variable-syntax/#advanced-variable-format-options
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/variable-syntax/#advanced-variable-format-options
|
||||
add-template-variables:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/add-template-variables/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/add-template-variables/
|
||||
---
|
||||
|
||||
# MySQL template variables
|
||||
|
||||
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 **template variables**.
|
||||
|
||||
For an introduction to templating and template variables, refer to [Templating](ref:variables) and [Add and manage variables](ref:add-template-variables).
|
||||
|
||||
## Query variable
|
||||
|
||||
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.
|
||||
|
||||
For example, the following query returns all values from the `hostname` column:
|
||||
|
||||
```sql
|
||||
SELECT hostname FROM my_host
|
||||
```
|
||||
|
||||
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 `hostname` and `hostname2` columns, which are included in the variable's drop-down list.
|
||||
|
||||
```sql
|
||||
SELECT my_host.hostname, my_other_host.hostname2 FROM my_host JOIN my_other_host ON my_host.city = my_other_host.city
|
||||
```
|
||||
|
||||
To use time range dependent macros like `$__timeFilter(column)` in your query, you must set the template variable's refresh mode to **On Time Range Change**.
|
||||
|
||||
```sql
|
||||
SELECT event_name FROM event_log WHERE $__timeFilter(time_column)
|
||||
```
|
||||
|
||||
### Key/value variables
|
||||
|
||||
You can create a key/value variable using a query that returns two columns named `__text` and `__value`.
|
||||
|
||||
- The `__text` column defines the label shown in the drop-down.
|
||||
- The `__value` column defines the value passed to panel queries.
|
||||
|
||||
This is useful when you want to display a user-friendly label (like a hostname) but use a different underlying value (like an ID).
|
||||
|
||||
Note that the values in the `__text` column should be unique. If there are duplicates, Grafana uses only the first matching entry.
|
||||
|
||||
```sql
|
||||
SELECT hostname AS __text, id AS __value FROM my_host
|
||||
```
|
||||
|
||||
### Nested variables
|
||||
|
||||
You can create nested variables, where one variable depends on the value of another. For example, if you have a variable named `region`, you can configure a `hosts` variable to only show hosts from the selected region. If `region` is a multi-value variable, use the `IN` operator instead of `=` to match against multiple selected values.
|
||||
|
||||
```sql
|
||||
SELECT hostname FROM my_host WHERE region IN($region)
|
||||
```
|
||||
|
||||
### Filter results with `__searchFilter`
|
||||
|
||||
Using `__searchFilter` in the query field allows the query results to be filtered based on the user's input in the drop-down selection box. If you don't enter anything, the default value for `__searchFilter` is `%`.
|
||||
|
||||
Note that you must enclose the `__searchFilter` expression in quotes as Grafana doesn't add them automatically.
|
||||
|
||||
The following example demonstrates how to use `__searchFilter` in the query field to enable real-time searching for `hostname` as the user types in the drop-down selection box.
|
||||
|
||||
```sql
|
||||
SELECT hostname FROM my_host WHERE hostname LIKE '$__searchFilter'
|
||||
```
|
||||
|
||||
## Use variables in queries
|
||||
|
||||
Grafana automatically quotes template variable values only when the template variable is a `multi-value`.
|
||||
|
||||
When using a multi-value variable, use the `IN` comparison operator instead of `=` to match against multiple values.
|
||||
|
||||
Grafana supports two syntaxes for using variables in queries:
|
||||
|
||||
- **`$<varname>` syntax**
|
||||
|
||||
Example with a template variable named `hostname`:
|
||||
|
||||
```sql
|
||||
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
|
||||
```
|
||||
|
||||
- **`[[varname]]` syntax**
|
||||
|
||||
Example with a template variable named `hostname`:
|
||||
|
||||
```sql
|
||||
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
|
||||
```
|
||||
|
||||
### Disable quoting for multi-value variables
|
||||
|
||||
By default, Grafana formats multi-value variables as a quoted, comma-separated string. For example, if `server01` and `server02` are selected, the result will be `'server01'`, `'server02'`. To disable quoting, use the `csv` formatting option for variables:
|
||||
|
||||
```text
|
||||
${servers:csv}
|
||||
```
|
||||
|
||||
This outputs the values as an unquoted comma-separated list.
|
||||
|
||||
Refer to [Advanced variable format options](ref:variable-syntax-advanced-variable-format-options) for additional information.
|
||||
@@ -1,80 +0,0 @@
|
||||
---
|
||||
description: Learn how to troubleshoot common problems with the Grafana MySQL data source plugin
|
||||
keywords:
|
||||
- grafana
|
||||
- mysql
|
||||
- query
|
||||
labels:
|
||||
products:
|
||||
- cloud
|
||||
- enterprise
|
||||
- oss
|
||||
menuTitle: Troubleshoot
|
||||
title: Troubleshoot common problems with the Grafana MySQL data source plugin
|
||||
weight: 40
|
||||
refs:
|
||||
variables:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/dashboards/variables/
|
||||
variable-syntax-advanced-variable-format-options:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/variables/variable-syntax/#advanced-variable-format-options
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/dashboards/variables/variable-syntax/#advanced-variable-format-options
|
||||
annotate-visualizations:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/dashboards/build-dashboards/annotate-visualizations/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/dashboards/build-dashboards/annotate-visualizations/
|
||||
explore:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/explore/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/explore/
|
||||
query-transform-data:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/panels-visualizations/query-transform-data/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/panels-visualizations/query-transform-data/
|
||||
panel-inspector:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/panels-visualizations/panel-inspector/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/panels-visualizations/panel-inspector/
|
||||
query-editor:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/panels-visualizations/query-transform-data/#query-editors
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/visualizations/panels-visualizations/query-transform-data/#query-editors
|
||||
alert-rules:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/alerting/fundamentals/alert-rules/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/alerting-and-irm/alerting/alerting-rules/
|
||||
template-annotations-and-labels:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/alerting/alerting-rules/templates/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/alerting-and-irm/alerting/alerting-rules/templates/
|
||||
configure-standard-options:
|
||||
- pattern: /docs/grafana/
|
||||
- destination: /docs/grafana/<GRAFANA_VERSION>/panels-visualizations/configure-standard-options/
|
||||
---
|
||||
|
||||
# Troubleshoot common problems with the Grafana MySQL data source plugin
|
||||
|
||||
This page lists common issues you might experience when setting up the Grafana MySQL data source plugin.
|
||||
|
||||
### My data source connection fails when using the Grafana MySQL data source plugin
|
||||
|
||||
- Check if the MySQL server is up and running.
|
||||
- Make sure that your firewall is open for MySQL server (default port is `3306`).
|
||||
- Ensure that you have the correct permissions to access the MySQL server and also have permission to access the database.
|
||||
- If the error persists, create a new user for the Grafana MySQL data source plugin with correct permissions and try to connect with it.
|
||||
|
||||
### What should I do if I see "An unexpected error happened" or "Could not connect to MySQL" after trying all of the above?
|
||||
|
||||
- Check the Grafana logs for more details about the error.
|
||||
- For Grafana Cloud customers, contact support.
|
||||
370
docs/sources/datasources/mysql/troubleshooting/index.md
Normal file
370
docs/sources/datasources/mysql/troubleshooting/index.md
Normal file
@@ -0,0 +1,370 @@
|
||||
---
|
||||
aliases:
|
||||
- ../troubleshoot/
|
||||
description: Troubleshoot common problems with the MySQL data source in Grafana
|
||||
keywords:
|
||||
- grafana
|
||||
- mysql
|
||||
- troubleshooting
|
||||
- errors
|
||||
labels:
|
||||
products:
|
||||
- cloud
|
||||
- enterprise
|
||||
- oss
|
||||
menuTitle: Troubleshooting
|
||||
title: Troubleshoot MySQL data source issues
|
||||
weight: 400
|
||||
refs:
|
||||
configure-mysql-data-source:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/configure/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/configure/
|
||||
mysql-query-editor:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/query-editor/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana/<GRAFANA_VERSION>/datasources/mysql/query-editor/
|
||||
private-data-source-connect:
|
||||
- pattern: /docs/grafana/
|
||||
destination: /docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/
|
||||
- pattern: /docs/grafana-cloud/
|
||||
destination: /docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/
|
||||
---
|
||||
|
||||
# Troubleshoot MySQL data source issues
|
||||
|
||||
This document provides solutions to common issues you may encounter when configuring or using the MySQL data source in Grafana.
|
||||
|
||||
## Connection errors
|
||||
|
||||
These errors occur when Grafana cannot establish or maintain a connection to the MySQL server.
|
||||
|
||||
### Unable to connect to the server
|
||||
|
||||
**Error message:** "dial tcp: connection refused" or "Could not connect to MySQL"
|
||||
|
||||
**Cause:** Grafana cannot establish a network connection to the MySQL server.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Verify that the MySQL server is running and accessible.
|
||||
1. Check that the host and port are correct in the data source configuration. The default MySQL port is `3306`.
|
||||
1. Ensure there are no firewall rules blocking the connection between Grafana and MySQL.
|
||||
1. Verify that MySQL is configured to allow remote connections by checking the `bind-address` setting in your MySQL configuration.
|
||||
1. For Grafana Cloud, ensure you have configured [Private data source connect](ref:private-data-source-connect) if your MySQL instance isn't publicly accessible.
|
||||
|
||||
### Connection timeout
|
||||
|
||||
**Error message:** "Connection timed out" or "I/O timeout"
|
||||
|
||||
**Cause:** The connection to MySQL timed out before receiving a response.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Check the network latency between Grafana and MySQL.
|
||||
1. Verify that MySQL isn't overloaded or experiencing performance issues.
|
||||
1. Check if any network devices (load balancers, proxies) are timing out the connection.
|
||||
1. Increase the `wait_timeout` setting in MySQL if connections are timing out during idle periods.
|
||||
|
||||
### TLS/SSL connection failures
|
||||
|
||||
**Error message:** "TLS handshake failed" or "x509: certificate verify failed"
|
||||
|
||||
**Cause:** There is a mismatch between the TLS settings in Grafana and what the MySQL server supports or requires.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Verify that the MySQL server has a valid SSL certificate if encryption is enabled.
|
||||
1. Check that the certificate is trusted by the Grafana server.
|
||||
1. If using a self-signed certificate, enable **With CA Cert** and provide the root certificate under **TLS/SSL Root Certificate**.
|
||||
1. To bypass certificate validation (not recommended for production), enable **Skip TLS Verification** in the data source configuration.
|
||||
1. Ensure the SSL certificate hasn't expired.
|
||||
|
||||
### Connection reset by peer
|
||||
|
||||
**Error message:** "Connection reset by peer" or "EOF"
|
||||
|
||||
**Cause:** The MySQL server closed the connection unexpectedly.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Check the `max_connections` setting on the MySQL server to ensure it isn't being exceeded.
|
||||
1. Verify the `wait_timeout` and `interactive_timeout` settings in MySQL aren't set too low.
|
||||
1. Increase the **Max lifetime** setting in Grafana's data source configuration to be lower than MySQL's `wait_timeout`.
|
||||
1. Check MySQL server logs for any errors or connection-related messages.
|
||||
|
||||
## Authentication errors
|
||||
|
||||
These errors occur when there are issues with authentication credentials or permissions.
|
||||
|
||||
### Access denied for user
|
||||
|
||||
**Error message:** "Access denied for user 'username'@'host'" or "Authentication failed"
|
||||
|
||||
**Cause:** The authentication credentials are invalid or the user doesn't have permission to connect from the Grafana server's host.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Verify that the username and password are correct.
|
||||
1. Check that the user exists in MySQL and is enabled.
|
||||
1. Ensure the user has permission to connect from the Grafana server's IP address. MySQL restricts access based on the connecting host:
|
||||
|
||||
```sql
|
||||
SELECT user, host FROM mysql.user WHERE user = 'your_user';
|
||||
```
|
||||
|
||||
1. If necessary, create a user that can connect from the Grafana server:
|
||||
|
||||
```sql
|
||||
CREATE USER 'grafana'@'grafana_server_ip' IDENTIFIED BY 'password';
|
||||
```
|
||||
|
||||
1. If using the `mysql_native_password` authentication plugin, ensure it's enabled on the server.
|
||||
|
||||
### Cannot access database
|
||||
|
||||
**Error message:** "Access denied for user 'username'@'host' to database 'dbname'"
|
||||
|
||||
**Cause:** The authenticated user doesn't have permission to access the specified database.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Verify that the database name is correct in the data source configuration.
|
||||
1. Ensure the user has the required permissions on the database:
|
||||
|
||||
```sql
|
||||
GRANT SELECT ON your_database.* TO 'grafana'@'grafana_server_ip';
|
||||
FLUSH PRIVILEGES;
|
||||
```
|
||||
|
||||
1. For production environments, grant permissions only on specific tables:
|
||||
|
||||
```sql
|
||||
GRANT SELECT ON your_database.your_table TO 'grafana'@'grafana_server_ip';
|
||||
```
|
||||
|
||||
### PAM authentication issues
|
||||
|
||||
**Error message:** "Authentication plugin 'auth_pam' cannot be loaded" or cleartext password errors
|
||||
|
||||
**Cause:** PAM (Pluggable Authentication Modules) authentication requires cleartext password transmission.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Enable **Allow Cleartext Passwords** in the data source configuration if using PAM authentication.
|
||||
1. Ensure TLS is enabled to protect password transmission when using cleartext passwords.
|
||||
1. Verify that the PAM plugin is correctly installed and configured on the MySQL server.
|
||||
|
||||
## Query errors
|
||||
|
||||
These errors occur when there are issues with query syntax or configuration.
|
||||
|
||||
### Time column not found or invalid
|
||||
|
||||
**Error message:** "Could not find time column" or time series visualization shows no data
|
||||
|
||||
**Cause:** The query doesn't return a properly formatted `time` column for time series visualization.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Ensure your query includes a column named `time` when using the **Time series** format.
|
||||
1. Use the `$__time()` macro to convert your date column: `$__time(your_date_column)`.
|
||||
1. Verify the time column is of a valid MySQL date/time type (`DATETIME`, `TIMESTAMP`, `DATE`) or contains Unix epoch values.
|
||||
1. Ensure the result set is sorted by the time column using `ORDER BY`.
|
||||
|
||||
### Macro expansion errors
|
||||
|
||||
**Error message:** "Error parsing query" or macros appear unexpanded in the query
|
||||
|
||||
**Cause:** Grafana macros are being used incorrectly.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Verify macro syntax: use `$__timeFilter(column)` not `$_timeFilter(column)`.
|
||||
1. Check that the column name passed to macros exists in your table.
|
||||
1. View the expanded query by clicking **Generated SQL** after running the query to debug macro expansion.
|
||||
1. Ensure backticks are used for reserved words or special characters in column names: `$__timeFilter(\`time-column\`)`.
|
||||
|
||||
### Timezone and time shift issues
|
||||
|
||||
**Cause:** Time series data appears shifted or doesn't align with expected times.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Store timestamps in UTC in your database to avoid timezone issues.
|
||||
1. Time macros (`$__time`, `$__timeFilter`, etc.) always expand to UTC values.
|
||||
1. Set the **Session Timezone** in the data source configuration to match your data's timezone, or use `+00:00` for UTC.
|
||||
1. If your timestamps are stored in local time, convert them to UTC in your query:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
CONVERT_TZ(your_datetime_column, 'Your/Timezone', 'UTC') AS time,
|
||||
value
|
||||
FROM your_table
|
||||
```
|
||||
|
||||
### Query returns too many rows
|
||||
|
||||
**Error message:** "Result set too large" or browser becomes unresponsive
|
||||
|
||||
**Cause:** The query returns more data than can be efficiently processed.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Add time filters using `$__timeFilter(column)` to limit data to the dashboard time range.
|
||||
1. Use aggregations (`AVG`, `SUM`, `COUNT`) with `GROUP BY` instead of returning raw rows.
|
||||
1. Add a `LIMIT` clause to restrict results: `SELECT ... LIMIT 1000`.
|
||||
1. Use the `$__timeGroup()` macro to aggregate data into time intervals.
|
||||
|
||||
### Syntax error in SQL statement
|
||||
|
||||
**Error message:** "You have an error in your SQL syntax" followed by specific error details
|
||||
|
||||
**Cause:** The SQL query contains invalid syntax.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Check for missing or extra commas, parentheses, or quotes.
|
||||
1. Ensure reserved words used as identifiers are enclosed in backticks: `` `table` ``, `` `select` ``.
|
||||
1. Verify that template variable syntax is correct: `$variable` or `${variable}`.
|
||||
1. Test the query directly in a MySQL client to isolate Grafana-specific issues.
|
||||
|
||||
### Unknown column in field list
|
||||
|
||||
**Error message:** "Unknown column 'column_name' in 'field list'"
|
||||
|
||||
**Cause:** The specified column doesn't exist in the table or is misspelled.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Verify the column name is spelled correctly.
|
||||
1. Check that the column exists in the specified table.
|
||||
1. If the column name contains special characters or spaces, enclose it in backticks: `` `column-name` ``.
|
||||
1. Ensure the correct database is selected if you're referencing columns without the full table path.
|
||||
|
||||
## Performance issues
|
||||
|
||||
These issues relate to slow queries or high resource usage.
|
||||
|
||||
### Slow query execution
|
||||
|
||||
**Cause:** Queries take a long time to execute.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Reduce the dashboard time range to limit data volume.
|
||||
1. Add indexes to columns used in `WHERE` clauses and time filters:
|
||||
|
||||
```sql
|
||||
CREATE INDEX idx_time ON your_table(time_column);
|
||||
```
|
||||
|
||||
1. Use aggregations instead of returning individual rows.
|
||||
1. Increase the **Min time interval** setting to reduce the number of data points.
|
||||
1. Review the query execution plan using `EXPLAIN` to identify bottlenecks:
|
||||
|
||||
```sql
|
||||
EXPLAIN SELECT * FROM your_table WHERE time_column > NOW() - INTERVAL 1 HOUR;
|
||||
```
|
||||
|
||||
### Connection pool exhaustion
|
||||
|
||||
**Error message:** "Too many connections" or "Connection pool exhausted"
|
||||
|
||||
**Cause:** Too many concurrent connections to the database.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Increase the **Max open** connection limit in the data source configuration.
|
||||
1. Enable **Auto (max idle)** to automatically manage idle connections.
|
||||
1. Reduce the number of panels querying the same data source simultaneously.
|
||||
1. Check for long-running queries that might be holding connections.
|
||||
1. Increase the `max_connections` setting in MySQL if necessary:
|
||||
|
||||
```sql
|
||||
SHOW VARIABLES LIKE 'max_connections';
|
||||
SET GLOBAL max_connections = 200;
|
||||
```
|
||||
|
||||
### Query timeout
|
||||
|
||||
**Error message:** "Query execution was interrupted" or "Lock wait timeout exceeded"
|
||||
|
||||
**Cause:** The query takes too long and exceeds the configured timeout.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Optimize the query by adding appropriate indexes.
|
||||
1. Reduce the amount of data being queried by narrowing the time range.
|
||||
1. Use aggregations to reduce the result set size.
|
||||
1. Check for table locks that might be blocking the query.
|
||||
|
||||
## Other common issues
|
||||
|
||||
The following issues don't produce specific error messages but are commonly encountered.
|
||||
|
||||
### Template variable queries fail
|
||||
|
||||
**Cause:** Variable queries return unexpected results or errors.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Verify the variable query syntax is valid SQL that returns a single column.
|
||||
1. Check that the data source connection is working.
|
||||
1. Ensure the user has permission to access the tables referenced in the variable query.
|
||||
1. Test the query in the query editor before using it as a variable query.
|
||||
|
||||
### Data appears incorrect or misaligned
|
||||
|
||||
**Cause:** Data formatting or type conversion issues.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Use explicit column aliases to ensure consistent naming: `SELECT value AS metric`.
|
||||
1. Verify numeric columns are actually numeric types, not strings.
|
||||
1. Check for `NULL` values that might affect aggregations.
|
||||
1. Use the `FILL` option in `$__timeGroup()` macro to handle missing data points.
|
||||
|
||||
### Special characters in database or table names
|
||||
|
||||
**Cause:** Queries fail when tables or databases contain reserved words or special characters.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Enclose identifiers with special characters in backticks: `` `my-database`.`my-table` ``.
|
||||
1. The query editor automatically handles this for selections, but manual queries require backticks.
|
||||
1. Avoid using reserved words as identifiers when possible.
|
||||
|
||||
### An unexpected error happened
|
||||
|
||||
**Error message:** "An unexpected error happened"
|
||||
|
||||
**Cause:** A general error occurred that doesn't have a specific error message.
|
||||
|
||||
**Solution:**
|
||||
|
||||
1. Check the Grafana server logs for more details about the error.
|
||||
1. Verify all data source configuration settings are correct.
|
||||
1. Test the connection using the **Save & test** button.
|
||||
1. Ensure the MySQL server is accessible and responding to queries.
|
||||
1. For Grafana Cloud customers, contact support for assistance.
|
||||
|
||||
## Get additional help
|
||||
|
||||
If you continue to experience issues after following this troubleshooting guide:
|
||||
|
||||
1. Check the [Grafana community forums](https://community.grafana.com/) for similar issues.
|
||||
1. Review the [Grafana GitHub issues](https://github.com/grafana/grafana/issues) for known bugs.
|
||||
1. Enable debug logging in Grafana to capture detailed error information.
|
||||
1. Check MySQL error logs for additional details.
|
||||
1. Contact Grafana Support if you're an Enterprise or Cloud customer.
|
||||
|
||||
When reporting issues, include:
|
||||
|
||||
- Grafana version
|
||||
- MySQL version
|
||||
- Error messages (redact sensitive information)
|
||||
- Steps to reproduce
|
||||
- Relevant query examples (redact sensitive data)
|
||||
Reference in New Issue
Block a user