docs/sources/datasources/mysql/troubleshooting/index.md
This document provides solutions to common issues you may encounter when configuring or using the MySQL data source in Grafana.
These errors occur when Grafana cannot establish or maintain a connection to the MySQL 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:
3306.bind-address setting in your MySQL configuration.Error message: "Connection timed out" or "I/O timeout"
Cause: The connection to MySQL timed out before receiving a response.
Solution:
wait_timeout setting in MySQL if connections are timing out during idle periods.TLS errors occur when the MySQL server requires or expects encrypted connections but the Grafana data source isn't configured to match. Common error messages include:
Possible causes and solutions:
| Cause | Solution |
|---|---|
MySQL has require_secure_transport enabled or AWS RDS Proxy enforces TLS | Enable With CA Cert or Skip TLS Verification in the data source configuration. Either option establishes a TLS connection. |
| Self-signed or private CA certificate isn't trusted | Enable With CA Cert and provide the root certificate under TLS/SSL Root Certificate. |
| Certificate has expired or doesn't match the hostname | Renew the certificate, or enable Skip TLS Verification for development environments only. |
| TLS handshake fails against AWS RDS or RDS Proxy | Provide the Amazon RDS root CA certificate under TLS/SSL Root Certificate with With CA Cert enabled. |
| Organization requires mutual TLS (mTLS) | Enable Use TLS Client Auth and provide both a client certificate and key in addition to the CA certificate. |
{{< admonition type="note" >}} Skip TLS Verification and With CA Cert both establish encrypted connections. You don't need Use TLS Client Auth unless your setup requires mutual TLS. For most AWS RDS and RDS Proxy connections, With CA Cert with the Amazon root CA is sufficient. {{< /admonition >}}
For provisioned data sources, enable TLS in jsonData:
jsonData:
tlsAuthWithCACert: true
secureJsonData:
tlsCACert: ${CA_CERT}
To skip certificate validation instead, use:
jsonData:
tlsSkipVerify: true
For all available TLS provisioning options, refer to the TLS provisioning examples.
Error message: "Connection reset by peer" or "EOF"
Cause: The MySQL server closed the connection unexpectedly.
Solution:
max_connections setting on the MySQL server to ensure it isn't being exceeded.wait_timeout and interactive_timeout settings in MySQL aren't set too low.wait_timeout.These errors occur when there are issues with authentication credentials or permissions.
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:
Verify that the username and password are correct.
Check that the user exists in MySQL and is enabled.
Ensure the user has permission to connect from the Grafana server's IP address. MySQL restricts access based on the connecting host:
SELECT user, host FROM mysql.user WHERE user = 'your_user';
If necessary, create a user that can connect from the Grafana server:
CREATE USER 'grafana'@'grafana_server_ip' IDENTIFIED BY 'password';
If using the mysql_native_password authentication plugin, ensure it's enabled on the server.
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:
Verify that the database name is correct in the data source configuration.
Ensure the user has the required permissions on the database:
GRANT SELECT ON your_database.* TO 'grafana'@'grafana_server_ip';
FLUSH PRIVILEGES;
For production environments, grant permissions only on specific tables:
GRANT SELECT ON your_database.your_table TO 'grafana'@'grafana_server_ip';
Error message: "Authentication plugin 'auth_pam' cannot be loaded" or cleartext password errors
Cause: PAM (Pluggable Authentication Modules) authentication requires cleartext password transmission.
Solution:
These errors occur when there are issues with query syntax or configuration.
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:
time when using the Time series format.$__time() macro to convert your date column: $__time(your_date_column).DATETIME, TIMESTAMP, DATE) or contains Unix epoch values.ORDER BY.Error message: "Error parsing query" or macros appear unexpanded in the query
Cause: Grafana macros are being used incorrectly.
Solution:
$__timeFilter(column) not $_timeFilter(column).$__timeFilter(\time-column`)`.Error message: Query returns unexpected results or errors when string values contain #
Cause: In versions before Grafana 13.0, the SQL comment stripping logic incorrectly treated # inside quoted strings (for example, WHERE color = '#FF0000') as a comment delimiter, which stripped the rest of the line.
Solution:
# inside quoted strings.CONCAT function or a hexadecimal literal to avoid the # character in string literals.Cause: Time series data appears shifted or doesn't align with expected times.
Solution:
Store timestamps in UTC in your database to avoid timezone issues.
Time macros ($__time, $__timeFilter, etc.) always expand to UTC values.
Set the Session Timezone in the data source configuration to match your data's timezone, or use +00:00 for UTC.
If your timestamps are stored in local time, convert them to UTC in your query:
SELECT
CONVERT_TZ(your_datetime_column, 'Your/Timezone', 'UTC') AS time,
value
FROM your_table
Error message: "Result set too large" or browser becomes unresponsive
Cause: The query returns more data than can be efficiently processed.
Solution:
$__timeFilter(column) to limit data to the dashboard time range.AVG, SUM, COUNT) with GROUP BY instead of returning raw rows.LIMIT clause to restrict results: SELECT ... LIMIT 1000.$__timeGroup() macro to aggregate data into time intervals.Error message: "You have an error in your SQL syntax" followed by specific error details
Cause: The SQL query contains invalid syntax.
Solution:
`table`, `select`.$variable or ${variable}.Error message: "Unknown column 'column_name' in 'field list'"
Cause: The specified column doesn't exist in the table or is misspelled.
Solution:
`column-name`.CASE expression fails on non-standard string column typesError message: Query with CASE WHEN returns an error or unexpected results in Grafana, but works in other MySQL clients
Cause: The Grafana MySQL driver doesn't handle all MySQL string subtypes (such as ENUM, SET, TINYTEXT, or MEDIUMTEXT) in CASE expressions. The driver may fail to infer the result type correctly.
Solution:
Use CAST() to normalize the column to CHAR before using it in a CASE expression:
SELECT
CASE WHEN CAST(status_column AS CHAR) = 'active' THEN 1 ELSE 0 END AS is_active
FROM my_table
This is a known limitation of the Go MySQL driver used by Grafana. Explicitly casting to CHAR ensures consistent type handling.
These issues relate to slow queries or high resource usage.
Cause: Queries take a long time to execute.
Solution:
Reduce the dashboard time range to limit data volume.
Add indexes to columns used in WHERE clauses and time filters:
CREATE INDEX idx_time ON your_table(time_column);
Use aggregations instead of returning individual rows.
Increase the Min time interval setting to reduce the number of data points.
Review the query execution plan using EXPLAIN to identify bottlenecks:
EXPLAIN SELECT * FROM your_table WHERE time_column > NOW() - INTERVAL 1 HOUR;
Error message: "Too many connections" or "Connection pool exhausted"
Cause: Too many concurrent connections to the database.
Solution:
Increase the Max open connection limit in the data source configuration.
Enable Auto (max idle) to automatically manage idle connections.
Reduce the number of panels querying the same data source simultaneously.
Check for long-running queries that might be holding connections.
Increase the max_connections setting in MySQL if necessary:
SHOW VARIABLES LIKE 'max_connections';
SET GLOBAL max_connections = 200;
Error message: "Query execution was interrupted" or "Lock wait timeout exceeded"
Cause: The query takes too long and exceeds the configured timeout.
Solution:
The following issues don't produce specific error messages but are commonly encountered.
Cause: Variable queries return unexpected results or errors.
Solution:
Cause: Data formatting or type conversion issues.
Solution:
SELECT value AS metric.NULL values that might affect aggregations.FILL option in $__timeGroup() macro to handle missing data points.Cause: Queries fail when tables or databases contain reserved words or special characters.
Solution:
`my-database`.`my-table`.Cause: When a MySQL data source is provisioned via YAML, the query caching toggle in the UI is greyed out. YAML provisioning doesn't currently support setting caching configuration.
Solution:
Use the Grafana HTTP API to enable query caching on the provisioned data source. Send a PUT request to update the data source with caching enabled:
curl -X PUT -H "Content-Type: application/json" \
-H "Authorization: Bearer <API_TOKEN>" \
"https://<GRAFANA_URL>/api/datasources/<DATASOURCE_ID>" \
-d '{
"jsonData": {
"queryCachingTTL": 300
}
}'
Replace <API_TOKEN> with a valid Grafana API token, <GRAFANA_URL> with your Grafana instance URL, and <DATASOURCE_ID> with the numeric ID of the data source. Set queryCachingTTL to the desired cache duration in seconds.
Retrieve the data source ID by calling GET /api/datasources/name/<DATA_SOURCE_NAME>.
YAML-based caching configuration is an open feature request. Check Grafana GitHub issues for current status.
{{< admonition type="note" >}} Query caching is available in Grafana Enterprise and Grafana Cloud. For more information, refer to Query and resource caching. {{< /admonition >}}
Error message: "An unexpected error happened"
Cause: A general error occurred that doesn't have a specific error message.
Solution:
If you continue to experience issues after following this troubleshooting guide:
When reporting issues, include: