Cronjob or MySQL event?

Michael Eilers Smith picture Michael Eilers Smith · Feb 11, 2013 · Viewed 24.4k times · Source

I have to update my MySQL database every hour, and I was wondering what the advantages/disadvantages of using a cronjob VS a MySQL event? For example, which is faster? Which is safer? Thanks!

Answer

Bohemian picture Bohemian · Feb 11, 2013

I would always go a cron job, because:

  • That's where sysadmins will expect it to be (this point is not to be underestimated)
  • crobtab is bullet-proof, time-tested, extremely widely used and understood
  • You can freely direct/analyse error/success messages where you want
  • Some database tasks require/prefer mysql to be off-line (eg full backup), so you've got to use cron for those - it's a bad idea to have some tasks done with cron and some done with mysql; you'll be unsure where to look
  • You can chain up other events that should follow if you've got a shell script

And finally, just because you can do something, doesn't mean it's a good idea. Mysql is good at data stuff. Don't use it for "shell" stuff.