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:
- Verify that the MySQL server is running and accessible.
- Check that the host and port are correct in the data source configuration. The default MySQL port is
3306. - Ensure there are no firewall rules blocking the connection between Grafana and MySQL.
- Verify that MySQL is configured to allow remote connections by checking the
bind-addresssetting in your MySQL configuration. - For Grafana Cloud, ensure you have configured 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:
- Check the network latency between Grafana and MySQL.
- Verify that MySQL isn’t overloaded or experiencing performance issues.
- Check if any network devices (load balancers, proxies) are timing out the connection.
- Increase the
wait_timeoutsetting 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:
- Verify that the MySQL server has a valid SSL certificate if encryption is enabled.
- Check that the certificate is trusted by the Grafana server.
- If using a self-signed certificate, enable With CA Cert and provide the root certificate under TLS/SSL Root Certificate.
- To bypass certificate validation (not recommended for production), enable Skip TLS Verification in the data source configuration.
- 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:
- Check the
max_connectionssetting on the MySQL server to ensure it isn’t being exceeded. - Verify the
wait_timeoutandinteractive_timeoutsettings in MySQL aren’t set too low. - Increase the Max lifetime setting in Grafana’s data source configuration to be lower than the MySQL
wait_timeout. - 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:
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_passwordauthentication 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:
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';
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:
- Enable Allow Cleartext Passwords in the data source configuration if using PAM authentication.
- Ensure TLS is enabled to protect password transmission when using cleartext passwords.
- 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:
- Ensure your query includes a column named
timewhen using the Time series format. - Use the
$__time()macro to convert your date column:$__time(your_date_column). - Verify the time column is of a valid MySQL date/time type (
DATETIME,TIMESTAMP,DATE) or contains Unix epoch values. - 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:
- Verify macro syntax: use
$__timeFilter(column)not$_timeFilter(column). - Check that the column name passed to macros exists in your table.
- View the expanded query by clicking Generated SQL after running the query to debug macro expansion.
- 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:
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:00for 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
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:
- Add time filters using
$__timeFilter(column)to limit data to the dashboard time range. - Use aggregations (
AVG,SUM,COUNT) withGROUP BYinstead of returning raw rows. - Add a
LIMITclause to restrict results:SELECT ... LIMIT 1000. - 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:
- Check for missing or extra commas, parentheses, or quotes.
- Ensure reserved words used as identifiers are enclosed in backticks:
`table`,`select`. - Verify that template variable syntax is correct:
$variableor${variable}. - 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:
- Verify the column name is spelled correctly.
- Check that the column exists in the specified table.
- If the column name contains special characters or spaces, enclose it in backticks:
`column-name`. - 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:
Reduce the dashboard time range to limit data volume.
Add indexes to columns used in
WHEREclauses 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
EXPLAINto identify bottlenecks: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:
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_connectionssetting in MySQL if necessary: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:
- Optimize the query by adding appropriate indexes.
- Reduce the amount of data being queried by narrowing the time range.
- Use aggregations to reduce the result set size.
- 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:
- Verify the variable query syntax is valid SQL that returns a single column.
- Check that the data source connection is working.
- Ensure the user has permission to access the tables referenced in the variable query.
- 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:
- Use explicit column aliases to ensure consistent naming:
SELECT value AS metric. - Verify numeric columns are actually numeric types, not strings.
- Check for
NULLvalues that might affect aggregations. - Use the
FILLoption 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:
- Enclose identifiers with special characters in backticks:
`my-database`.`my-table`. - The query editor automatically handles this for selections, but manual queries require backticks.
- 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:
- Check the Grafana server logs for more details about the error.
- Verify all data source configuration settings are correct.
- Test the connection using the Save & test button.
- Ensure the MySQL server is accessible and responding to queries.
- For Grafana Cloud customers, contact support for assistance.
Get additional help
If you continue to experience issues after following this troubleshooting guide:
- Check the Grafana community forums for similar issues.
- Review the Grafana GitHub issues for known bugs.
- Enable debug logging in Grafana to capture detailed error information.
- Check MySQL error logs for additional details.
- 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)



