Event Scheduler should execute every month

ぃ、小莉子 提交于 2019-12-19 07:35:25

问题


I have Win XP os and XAMPP installed in my machine.

I need to execute my event/scheduler at 12:00:00 AM of First day of every month. Means 1st of every month. (e.g. jan 1st, Feb1 1st, March 1st, ... ).

And I also need to call the stored procedure in the same event. And I want achieve all this using Event/Job only not from front end.

Please spend few minutes for my query.


回答1:


The MySQL event syntax is very simple -

DELIMITER $$
CREATE EVENT event1
ON SCHEDULE EVERY '1' MONTH
STARTS '2011-05-01 00:00:00'
DO 
BEGIN
 -- your code
END$$

DELIMITER ;

Event will start working on '2011-05-01' at '00:00:00' (datetime must be in a future).

More information - Using the Event Scheduler

Do not forget to enable global event scheduling thread -

SET GLOBAL event_scheduler = 1;



回答2:


Assuming your mysql database lives on a web server, you can set up a cron job that runs at the first of every month. Your server probably provides some web interface to do this.

If you can't start the cron job from the server itself, there are free web services where you can set up cron jobs that call scripts on your server at given times.

The script called by the cron job can be a simple php script that runs the query.

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
mysql_query(' /* insert query here */ ');
mysql_close($link);

You may want to include some error checking and either send yourself an email about success / failure or leave some messages in a log file. That way you can monitor whether the script runs at all and / or successfully.



来源:https://stackoverflow.com/questions/5712123/event-scheduler-should-execute-every-month

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!