http://dev.mysql.com/tech-resources/articles/event-feature.html
给个示例:
- SQL code
-
如果你是5.1后的版本的话,可以用event功能,示例如下: 检查event功能: mysql> show variables like '%sche%'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | event_scheduler | OFF | +-----------------+-------+ 1 row in set (0.01 sec) 启动event功能: mysql> set global event_scheduler =1; Query OK, 0 rows affected (0.00 sec) 确定起用event功能后,执行下面的建立event:(每24小时执行一次,任务的操作主体是update那部分) delimiter // create EVENT my_stat_event ON SCHEDULE EVERY 24 HOUR STARTS concat(date_format(now(),'%Y-%m-%d'),' 23:00:00') on completion preserve ENABLE do begin update order_total a inner join (select company_id, sum(goods_number) as total_count from order_goods group by company_id) b on a.company_id=b.company_id set a.total=b.total_count; end; // 执行上面的建立作业后,查看作业的信息: mysql> select * from information_schema.events where event_name='my_stat_event';