Search code examples
mysqlmysql-event

Schedule mysql event to run every chosen day of the week


i want to read my table logs after rotating my logs using an event and i want my event to run in any day of the week i choose.

After doing some research,i have come up with this

CREATE EVENT read_rotated_logs
ON SCHEDULE
  EVERY 1 WEEK
  STARTS CURRENT_DATE + INTERVAL 7 - WEEKDAY(CURRENT_DATE) DAY
    DO BEGIN

    END */$$
DELIMITER ;

Its not clear how i might arrive at a specific day of the week for example monday.How may i structure my code to make the event run on any speific day of the week (mon or tuesday or wednesday or thursday or friday or saturday or sunday)


Solution

  • Here is how you do it for the other days of the week

    Monday

    STARTS CURRENT_DATE + INTERVAL 0 - WEEKDAY(CURRENT_DATE) DAY
    

    Tuesday

    STARTS CURRENT_DATE + INTERVAL 1 - WEEKDAY(CURRENT_DATE) DAY
    

    and so on