【发布时间】:2009-11-14 06:01:49
【问题描述】:
我需要每 24 小时运行一次:
delete tags from tags left join tagowners on tags.id=tagowners.tagId
where tagowners.tagId is null;
【问题讨论】:
我需要每 24 小时运行一次:
delete tags from tags left join tagowners on tags.id=tagowners.tagId
where tagowners.tagId is null;
【问题讨论】:
CREATE EVENT cleartags
ON SCHEDULE EVERY 24 HOUR
DO
delete tags from tags left join tagowners on tags.id=tagowners.tagId
where tagowners.tagId is null;
【讨论】:
. . . EVERY 1 DAY 可以替代. . . EVERY 24 HOUR。
首先在 SQl 查询浏览器中执行此操作
设置全球 event_scheduler = ON;然后执行这个。它会在每 24 小时凌晨 12:00 触发一次
创建事件事件 1 按计划每“1”天 开始'2013-01-21 00:00:00' 做 从 tags 中删除标签 left join tagowners on tags.id=tagowners.tagId 其中 tagowners.tagId 为空;【讨论】:
与cron:
mysql -uUSER -pPWD -hDB-HOSTNAME/IPADDRESS -e "delete tags from tags left join tagowners on tags.id=tagowners.tagId where tagowners.tagId is null;"
【讨论】:
如果您使用的是 linux 服务器,您可以创建一个 cronjob,一个计划任务,通过 php 可执行文件执行 php 脚本。创建一个 cron 任务很容易,通过 shell 执行“crontab -e”,然后将你的命令添加到文件的底部。
来自http://mkaz.com/ref/unix_cron.html 的示例 cron 条目
#Run command at 7:00am each weekday [mon-fri]
00 07 * * 1-5 mail_pager.script 'Wake Up'
#Run command on 1st of each month, at 5:30pm
30 17 1 * * pay_rent.script
#Run command at 8:00am,10:00am and 2:00pm every day
00 8,10,14 * * * do_something.script
#Run command every 5 minutes during market hours
*/5 6-13 * * mon-fri get_stock_quote.script
#Run command every 3-hours while awake
0 7-23/3 * * * drink_water.script
如果你想每天执行一次 php 脚本...
0 0 * * * /path/to/php.exe myscript.php
请记住,您是通过 CLI 执行脚本,因此 $_GET/$_POST/$_SERVER 超级全局变量将不存在(您可以使用 wget 解决此问题)。
如果您在 Windows 上,您可以使用 Windows 任务计划程序来完成相同的操作。
【讨论】: