Create a MySQL account that can read exactly one database, point Grafana at it, and press Save & Test.
-- in MySQL
CREATE USER 'grafana_ro'@'10.0.0.5' IDENTIFIED BY '<long random password>';
GRANT SELECT ON appdb.* TO 'grafana_ro'@'10.0.0.5';
That is the whole grant. No ON *.*, no ON mysql.*, no PROCESS, no SUPER. Then the datasource — shown here as the API payload, because it names each field exactly as Grafana stores it:
{"name":"appdb","type":"mysql","access":"proxy","url":"10.0.0.5:3306",
"user":"grafana_ro","database":"appdb",
"jsonData":{"database":"appdb","maxOpenConns":4,"maxIdleConns":2,
"connMaxLifetime":14400,"tlsSkipVerify":true},
"secureJsonData":{"password":"<long random password>"}}
$ curl -sS -X POST "$GRAFANA/api/datasources/uid/$UID/health"
{"message": "Database Connection OK", "status": "OK"}
The password goes into secureJsonData, is encrypted in Grafana’s database, and is never returned again — reading the datasource back gives "secureJsonFields": {"password": true} and nothing else.
Table of Contents
What the least-privilege account can and cannot do
Queried through Grafana’s /api/ds/query endpoint, i.e. exactly as a panel would:
SELECT user, host FROM mysql.user -> db query error: query failed
DELETE FROM app_requests WHERE id = 1 -> db query error: query failed
SHOW DATABASES -> hw_graf, information_schema, performance_schema
Worth knowing: a single-database grant does not hide everything else. information_schema is always visible, and performance_schema stayed readable — the connection’s own session_status answered normally. Plan for a Grafana user being able to see server metadata; plan for it not being able to see other people’s data.
Never GRANT SELECT ON mysql.* to a dashboard
Here is what a broader grant buys an attacker who gets into your Grafana — or any Grafana user who can type SQL into a panel. The same query, run through a datasource whose account has SELECT ON *.*:
SELECT plugin, LENGTH(authentication_string) AS hash_len
FROM mysql.user WHERE user='app_billing';
caching_sha2_password | 70
That is the stored password verifier for a different account, readable from a dashboard panel. The full authentication_string comes back with it; only the length is printed here on purpose. mysql.user also exposes every account name, host pattern and privilege bit on the server — a complete map of what else to attack. Grant the one database, and if a panel needs server metrics, use performance_schema/sys or the mysqld_exporter, not the mysql schema.
TLS: encrypted is not the same as verified
With tlsSkipVerify: true, the connection from Grafana 13.1.3 to MySQL 8.4.10 was encrypted — the session reported its own cipher through the datasource:
SELECT variable_value FROM performance_schema.session_status WHERE variable_name='Ssl_cipher';
TLS_AES_128_GCM_SHA256
Skip-verify means the certificate is not checked, so anything that can intercept the TCP connection can present its own certificate and read every query and result. To actually verify, supply the CA (tlsAuthWithCACert: true plus tlsCACert in secureJsonData). Do that against a stock MySQL, whose certificates are auto-generated at first start, and it fails — correctly:
tls: failed to verify certificate: x509: cannot validate certificate for 127.0.0.1
because it doesn't contain any IP SANs
$ openssl x509 -in server-cert.pem -noout -subject
subject=CN=MySQL_Server_8.4.10_Auto_Generated_Server_Certificate
MySQL’s self-generated certificate carries a placeholder CN and no subject alternative names, so no client can validate it against a hostname or an IP. Verified TLS to MySQL means issuing a certificate whose SAN matches the address Grafana connects to. Until you have done that, skip-verify over a private network is a trade-off you should make knowingly, not the default you never looked at.
maxOpenConns and maxIdleConns are real limits
Grafana keeps a Go connection pool per datasource. With maxOpenConns: 4, maxIdleConns: 2, twelve concurrent three-second queries were fired at one datasource and MySQL’s own information_schema.processlist counted:
before any query: 0 connections
during 12 concurrent queries: 4 connections (maxOpenConns)
after the burst drained: 2 connections (maxIdleConns)
Queries beyond the fourth wait for a slot rather than opening a fifth connection. Size maxOpenConns against your MySQL max_connections and the number of Grafana instances, not against the number of panels — a wall of 30 panels refreshing together is exactly the burst this setting exists to flatten. connMaxLifetime (seconds) recycles connections so they do not outlive a failover or a wait_timeout.
grafana-mysql-configuration.sh starts a MySQL server and a Grafana of its own, asserts the least-privilege grant, the rejected queries, the password-hash leak from an over-privileged account, the cipher, the connection counts under maxOpenConns and maxIdleConns and the interpolation failed error, and stops both afterwards, so an install you already have plays no part.
Two things that will waste an hour
Change the admin password before anything else. If this is your first time logging in, the default username and password are both ‘admin’. Set admin_password in grafana.ini or GF_SECURITY_ADMIN_PASSWORD; with it set, admin:admin against the API returns 401.
Grafana rewrites your SQL before sending it. On 13.1.3, SELECT VERSION() and SELECT DATABASE() go through, but SELECT USER() and SELECT CURRENT_USER() are rejected by Grafana’s own macro interpolation before MySQL ever sees them:
SELECT VERSION() AS server -> [["8.4.10"]]
SELECT USER() AS who -> interpolation failed: invalid query
If a query that works in the mysql client fails in a panel with interpolation failed, the problem is in Grafana’s query pre-processing, not in your SQL. Rewrite it — performance_schema.threads or information_schema will usually give you the same fact.