1

I have a MySQL event, works fine so that's not my problem, the problem here is I want to execute that event on month n/5th/year n and on month n/19th/year n for example on 10/4/2016 and then on 10/19/2016 it is possible to combine both dates in one event? If not what could be a solution?

I'm thinking in this option:

1- Create 2 events, every month, one on day 5th the other on 19th.

Sorry for not post code but this is not a code question.

User1899289003
  • 850
  • 2
  • 21
  • 40
  • your question is a bit confusing. You could create an event with an if statement wrapping the block with a check on `curdate()` – Drew Oct 04 '16 at 20:09
  • I don't know how to explain it better, but your opinion could be a solution I understand just I don't have much clear if I use and if statement what should be my time interval to execute the event? – User1899289003 Oct 04 '16 at 20:14
  • idk. Maybe you want it to start the check everyday at noon. If so, with [This](http://stackoverflow.com/a/37901661/1816093) it would be `12:00:00` instead of `00:00:00` . Make sure you honor the `ON COMPLETION PRESERVE`. – Drew Oct 04 '16 at 20:18
  • That's the moment when my question comes, I don't want to execute the event everyday, I want to know if is possible to execute this event for example on October 4th and then on October 19th, as you can see I think that an option could be creating 2 different events, 1 for day 4th and the other for day 19th – User1899289003 Oct 04 '16 at 20:19
  • The event is sitting there scheduled by a thread seen in `SHOW PROCESSLIST`. It fires once a day, only once a day, hits the `IF` and bails out. Total time like minuscule. You are way too over micro optimizing this in thought and wasting billions of joules of energy on it versus just one event that has no impact on system performance. Then in a month you manually delete the event. Note, it is the Scheduler that has the thread mainly, sleeping. The event does not until fired. – Drew Oct 04 '16 at 20:22
  • 1
    In other words, Much to Do about Nothing. Focus on bigger issues :p – Drew Oct 04 '16 at 20:23

1 Answers1

0

You can use crontab to execute events for your possible date/time. Crontab accept 5 parameters to set execution date/time.

* * * * *  YOUR_COMMAND_TO_EXECUTE

Here every * is a single parameter for Contab.

* --> min (0 - 59)
* --> hour (0 - 23)
* --> day of month (1 - 31)
* --> month (1 - 12)
* --> day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is also Sunday)

Example

# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

Here is details about the crontab Overview

Sumon Sarker
  • 2,707
  • 1
  • 23
  • 36
  • MySQL built-in their event framework (high overview snippets [here](http://stackoverflow.com/a/32508935/1816093) ) for the exact purpose of eliminating `cron` – Drew Oct 04 '16 at 20:26
  • That said, in all fairness, in many hosting environments only cron is available (cannot be abused, say, not more than 1 can fire in a 15 minute time period, else your acct gets frozen). And Events are completely turned off so as to limit any one hoster consuming the server – Drew Oct 04 '16 at 20:29
  • Thank you for advance @Drew – Sumon Sarker Oct 04 '16 at 20:33