Search code examples
mysqlmysql-event

Mysql creating an Event that updates something every monday, friday and sunday for ever


Do you guys have any idea of how to do this in Mysql?? to Create only one event without using 'IF' that happens how many days i want forever? Ex: an Event that happens every mondey, friday and sunday!


Solution

  • There doesn't seem to be any syntax for what you're describing.

    If I had to do this with a MySQL EVENT, I'd implement this with an IF for the day of week (MySQL uses Sunday=1).

    CREATE EVENT MyEvent
     ON SCHEDULE EVERY 1 DAY
    DO BEGIN
      IF DAYOFWEEK(CURDATE()) IN (1, 2, 6) THEN
        ...whatever you want...
      END IF
    END
    

    But practically speaking, I don't use MySQL EVENTs. I use cron. Then one can specify to run on the three days of the week you want (cron uses Sunday=0):

    0 0 * * 0,1,5 myscript.sh