<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="events-overview">
      </a>
      27.4.1 Event Scheduler Overview
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045082244944">
  </a>
  <p>
   MySQL Events are tasks that run according to a schedule.
      Therefore, we sometimes refer to them as
   <span class="emphasis">
    <em>
     scheduled
    </em>
   </span>
   events. When you create an event,
      you are creating a named database object containing one or more
      SQL statements to be executed at one or more regular intervals,
      beginning and ending at a specific date and time. Conceptually,
      this is similar to the idea of the Unix
   <code class="literal">
    crontab
   </code>
   (also known as a
   <span class="quote">
    “
    <span class="quote">
     cron job
    </span>
    ”
   </span>
   ) or the Windows Task
      Scheduler.
  </p>
  <p>
   Scheduled tasks of this type are also sometimes known as
   <span class="quote">
    “
    <span class="quote">
     temporal triggers
    </span>
    ”
   </span>
   , implying that these are objects
      that are triggered by the passage of time. While this is
      essentially correct, we prefer to use the term
   <span class="emphasis">
    <em>
     events
    </em>
   </span>
   to avoid confusion with triggers of
      the type discussed in
   <a class="xref" href="triggers.html" title="27.3 Using Triggers">
    Section 27.3, “Using Triggers”
   </a>
   . Events should
      more specifically not be confused with
   <span class="quote">
    “
    <span class="quote">
     temporary
      triggers
    </span>
    ”
   </span>
   . Whereas a trigger is a database object whose
      statements are executed in response to a specific type of event
      that occurs on a given table, a (scheduled) event is an object
      whose statements are executed in response to the passage of a
      specified time interval.
  </p>
  <p>
   While there is no provision in the SQL Standard for event
      scheduling, there are precedents in other database systems, and
      you may notice some similarities between these implementations and
      that found in the MySQL Server.
  </p>
  <p>
   MySQL Events have the following major features and properties:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      In MySQL, an event is uniquely identified by its name and the
          schema to which it is assigned.
     </p>
    </li>
    <li class="listitem">
     <p>
      An event performs a specific action according to a schedule.
          This action consists of an SQL statement, which can be a
          compound statement in a
      <a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
       <code class="literal">
        BEGIN ...
          END
       </code>
      </a>
      block if desired (see
      <a class="xref" href="sql-compound-statements.html" title="15.6 Compound Statement Syntax">
       Section 15.6, “Compound Statement Syntax”
      </a>
      ). An event's timing
          can be either
      <span class="firstterm">
       one-time
      </span>
      or
      <span class="firstterm">
       recurrent
      </span>
      . A one-time
          event executes one time only. A recurrent event repeats its
          action at a regular interval, and the schedule for a recurring
          event can be assigned a specific start day and time, end day
          and time, both, or neither. (By default, a recurring event's
          schedule begins as soon as it is created, and continues
          indefinitely, until it is disabled or dropped.)
     </p>
     <p>
      If a repeating event does not terminate within its scheduling
          interval, the result may be multiple instances of the event
          executing simultaneously. If this is undesirable, you should
          institute a mechanism to prevent simultaneous instances. For
          example, you could use the
      <a class="link" href="locking-functions.html#function_get-lock">
       <code class="literal">
        GET_LOCK()
       </code>
      </a>
      function, or row or
          table locking.
     </p>
    </li>
    <li class="listitem">
     <p>
      Users can create, modify, and drop scheduled events using SQL
          statements intended for these purposes. Syntactically invalid
          event creation and modification statements fail with an
          appropriate error message.
      <span class="emphasis">
       <em>
        A user may include
          statements in an event's action which require privileges that
          the user does not actually have
       </em>
      </span>
      . The event creation
          or modification statement succeeds but the event's action
          fails. See
      <a class="xref" href="events-privileges.html" title="27.4.6 The Event Scheduler and MySQL Privileges">
       Section 27.4.6, “The Event Scheduler and MySQL Privileges”
      </a>
      for details.
     </p>
    </li>
    <li class="listitem">
     <p>
      Many of the properties of an event can be set or modified
          using SQL statements. These properties include the event's
          name, timing, persistence (that is, whether it is preserved
          following the expiration of its schedule), status (enabled or
          disabled), action to be performed, and the schema to which it
          is assigned. See
      <a class="xref" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
       Section 15.1.3, “ALTER EVENT Statement”
      </a>
      .
     </p>
     <p>
      The default definer of an event is the user who created the
          event, unless the event has been altered, in which case the
          definer is the user who issued the last
      <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
       <code class="literal">
        ALTER EVENT
       </code>
      </a>
      statement affecting
          that event. An event can be modified by any user having the
      <a class="link" href="privileges-provided.html#priv_event">
       <code class="literal">
        EVENT
       </code>
      </a>
      privilege on the database
          for which the event is defined. See
      <a class="xref" href="events-privileges.html" title="27.4.6 The Event Scheduler and MySQL Privileges">
       Section 27.4.6, “The Event Scheduler and MySQL Privileges”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      An event's action statement may include most SQL statements
          permitted within stored routines. For restrictions, see
      <a class="xref" href="stored-program-restrictions.html" title="27.8 Restrictions on Stored Programs">
       Section 27.8, “Restrictions on Stored Programs”
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
