MySQL: Generated Query does wrong time filtering

Dear all

I have a problem concerning Grafana with MySQL.
For example, I want to show values from the last five minutes. To do so, I choose “Last 5 minutes” from the quick ranges on the upper right corner. The problem that I have is that the generated SQL query is wrong: For example, at 10:30 it generates a time range from 9:25 to 9:30 in the WHERE clause.

SELECT
UNIX_TIMESTAMP(time) as time_sec,
T1 as value
FROM measurements
WHERE time BETWEEN ‘2018-11-14T09:25:00Z’ AND ‘2018-11-14T09:30:00Z’
ORDER BY time ASC

The graphics on the other hand shows data from 10:25 to 10:30, which is empty (“Data points outside time range”). How can I resolve this time inconsistency?

I have set the time zone to Local Browser time in the preference tab.

Thanks for your help and best regards,
Lukas

Maybe since Some SQL servers by default are set at UTC TIME ZONE… you gotta check that and change settings in SQL or time filter it accordingly by apply time differences in grafana…

Hi,
Thanks for the answer. I moved back to version 5.2.2 of Grafana. With that I have no problems, I don’t know why.
Best,
Lukas

This was fixed in Grafana v5.3.4, see https://github.com/grafana/grafana/issues/13769.

1 Like

Hi,
Thanks a lot for the link to this discussion.

I have been using the latest docker version - this did not work. With the 5.2.2 I don’t have any problems concerning this.

Best regards

What version/commit is that?

I think it was 5.3.4

Okay. The generated query should definitely be different on 5.3.4. Per default all date and times in a Grafana dashboard are converted to local browser time from UTC and the time range is reflecting the local browser time, but when you execute the query that time is converted to UTC and sent to Grafana backend. That’s why the query generated is 1 hour before what you see.

If it still not work I’m guessing you have some timezone combination that doesn’t work together. What timezone of Grafana server, what timezone in mysql database?

Hi,
I have been using the same time zones on both servers. With the exact same configurations it works on 5.2.2.

For further investigation, please try again with 5.3.4 (not docker latest, grafana:5.3.4) and include generated sql here. As you can see in referenced issue the fix has resolved the problem for a lot of people.

For me its alright to work with 5.2.2 at the time. When I have the time I can try to figure out more about this.

Sure. Sound good. Thanks