title: How to delete a MySQL record after a certain time
body: <p>I want to delete some messages from my MySQL database after 7 days.</p>
  
  <p>My message table rows have this format:
  id | message | date</p>
  
  <p>The date is a timestamp in the normal format; 2012-12-29 17:14:53</p>
  
  <p>I was thinking that an MySQL event would be the way to go instead of a cron job.</p>
  
  <p>I have what I guess is a simple question to an experienced SQL person, how do I code the delete messages portion in brackets below?</p>
  
  <p>An example would be appreciated, Thanks.</p>
  
  <pre><code> DELIMITER $$
     CREATE EVENT delete_event
     ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
     ON COMPLETION PRESERVE
    DO
      BEGIN
        DELETE messages WHERE date &gt;= (the current date - 7 days);
      END;
  $$;
  </code></pre>