How to create an event that runs every 24 hours?

I need this to run every 24 hours:

delete tags from tags left join tagowners on tags.id=tagowners.tagId where tagowners.tagId is null; 
+4
source share
5 answers
 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; 
+15
source

Do it first in SQl Query Browser

  SET GLOBAL event_scheduler = ON;

then do it. It will run every 24 hours at 12:00.

  CREATE EVENT event1
   ON SCHEDULE EVERY '1' DAY
   STARTS '2013-01-21 00:00:00'    
 DO 
 delete tags from tags left join tagowners on tags.id = tagowners.tagId
     where tagowners.tagId is null;
+3
source

Work on a Linux system? Use cron . I don't think MySQL has built-in functions to accomplish this.

0
source

With 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;" 
0
source

If you are on a linux server, you can create a cronjob, a scheduled task, execute a php script through the php executable. Creating a cron task is easy, run "crontab -e" through the shell, then add your command to the end of the file.

Example cron entries taken from http://mkaz.com/ref/unix_cron.html

 #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 

If you want to execute php script once a day ...

 0 0 * * * /path/to/php.exe myscript.php 

Remember that you are running the script through the CLI, so the $_GET / $_POST / $_SERVER super-globals will not exist (you can get around this with wget).

If you are in windows, you can use the Windows Task Scheduler to do the same.

0
source

All Articles