问题
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