"Cron Jobs" for MySQL in Lua

I’m looking for a way to run a MySQL query after X amount of time. I thought of saving the times & actions that need to be ran in json format, but wondered how am I supposed to make sure they actually run on time efficiently? In others words as soon as the time saved comes, run that instant. Any help/suggestions are appreciated!

You appear to be looking for the MySQL Event Scheduler

[editline]10th September 2016[/editline]

Or did you mean triggering some kind of save from GMod every x minutes or something like that?

Nope, you’re first answer is exactly what I’m looking for. I’ve actually never seen the MySQL Event Scheduler, I’ll have to look at it in more detail so I can figure out how to use it with my code.

[editline]10th September 2016[/editline]

If you could provide some simple examples, that would be fantastic. Also, can events be made through a query?


CREATE DEFINER=`mysqluser` EVENT `Reset Weekly Wins`
	ON SCHEDULE
		EVERY 1 WEEK STARTS '2013-01-06 01:00:00'
	ON COMPLETION PRESERVE
	ENABLE
	DO BEGIN
		UPDATE user_table SET weekly_wins = 0;
END

This would reset all players weekly win count every Sunday at 1am (MySQL server time). But you can basically just change the UPDATE user_table… line with anything you want to run. Pretty simple syntax. Just make sure you tell the event not to expire after it runs once. That’s what that PRESERVE line is for, and I’m not sure what the default behavior is.