List:General Discussion« Previous MessageNext Message »
From:Bruce MacDonald Date:December 5 2002 3:27am
Subject:Re: Trigger
View as plain text  

> I need to build a cache mechanism for a website and I thought I'd use
> for persistance.  The problem is that I need it to schedule a cleanup task
> every 24 hours - to remove old cache records.  MS SQL Server provides a
> trigger for scheduling such tasks - I am looking for the functional analog
> on MySQL.

Use a CRON job on the server to have mysql execute SQL statements in batch
mode periodically.

Write a shell script to invoke mysql in batch mode and take its input from a
file. Here's one example:

#! /bin/sh
/usr/bin/mysql -h localhost -u username -ppassword database-name

where the file 'commands.sql' contains the SQL statements to clean up the

Then add an entry to your CRONTAB. The following example would run the shell
script at 2am each day:

0 2 * * * /path/to/shellscript

See the CRONTAB manual on your system for details.

If using Windows to run your MySQL server, use the cmd interpreter, the 'at'
command, and the Schedule service. There are versions of CRON available for
Windows, too.

Bruce MacDonald
Minnesota Public Radio

Storing data or filestan hai shi4 Dec
  • Re: Storing data or filesThomas Spahni4 Dec
    • Triggerneal4 Dec
      • Re: TriggerGerald R. Jensen5 Dec
      • Re: TriggerBruce MacDonald5 Dec