Can not access MySQL db from grafana

grafana 8.0.3, Linux 18.04 LTS (in docker), DB: mariaDB(MySQL)

Would like to connect to the db to test connectivity. When I try to connect the db, it is not giving error in connectivity, but with status as ‘Testing …’ continuing forever, without actually ‘connecting’ to the db.

Steps to reproduce the problem:

  1. open grafana in a google chrome browser
  2. login with admin and my-password
  3. Name : grafana, host: localhost:3000, User grafana, Password (same as db)
    (in the grafana browser)

I have edited the /etc/grafana/grafana.ini - the server part as below:
type = mysql
host = 127.0.0.1:3000
name = grafana
user = grafana
password = my-password-for-the-db

Here one point I should mention. I have found that ‘;’ is used as comment-out, so I should remove it to make the editing effective. But if I remove the ‘;’ (semi-colon) I can not start grafana (failing). Means it is considering as an error. On the other hand, when I check the log (/var/log/grafana.log), even though I have changed the ‘type’ from ‘splite3’ to ‘mysql’, but it is still showing ‘splite3’.
So even though it is reading this ‘grafana.ini’ file, and reacting to the syntax error, but it is not actually taking any effect. At least it seems so to me.

How to solve the issue? I am very new to grafana. Just started to use it installing.

May be the connection is something different issue, not directly related to grafana. But at first would like to solve the config file problem.

Any help/tips would be very helpful.

Thanks.

Firstly, you don’t have to edit your .ini file at all to create a MySQL datasource. You just need to enter the correct details in the datasource settings GUI.

And it’s likely that you need to set the datasource Host to localhost:3306 Assuming your MySQL database is running on the same host and with the default port.

3000 is the default port for Grafana itself, not the port for your MySQL database.

1 Like

It did work. Connected to MySQL database instantly as it should.
Thank you so much. Its a great relief.

BTW, should I only edit the grafana.ini only if I need to change the default values? Such as, localhost:3306 to something different? And is the ‘;’ actually a comment-out?

Lines starting with # or ; are commented out.

I do not know what the database settings in the .ini file are for or what database is being configured there.

Thank you. Understood.