how to fire a Mysql trigger on an specific date and time

拥有回忆 提交于 2019-12-25 08:19:01

问题


I have to call a store procedure at the end of each month, i just need to know how to fire a trigger on an specific date and time to call my stored procedure.

Thanks for your time.


回答1:


MySQL can't do this. Instead, you should use a cronjob. If you're on a Linux system, you can create a script or program that runs your stored procedure and schedule it for execution using the crontab command.

In the command line, writing crontab -e will allow you to edit your cronjobs. In here, you can add

0 5 L * ? * /path/to/script.pl

This will run /path/to/script.pl at 5 AM, the last day of every month.




回答2:


MySQL triggers are responses to query events - the clock ticking is not one of them. If you need to execute something at a specific date/time, use an external job scheduler (e.g. cron) to trigger the job.

As stated in the MySQL docs:

MySQL triggers are activated by SQL statements only.



回答3:


What you can do is to create an event.

CREATE EVENT event_name
    ON SCHEDULE
      period_of_time
    DO
      your_code_here


来源:https://stackoverflow.com/questions/10076541/how-to-fire-a-mysql-trigger-on-an-specific-date-and-time

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