<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="replication-features-create-if-not-exists">
      </a>
      19.5.1.6 Replication of CREATE ... IF NOT EXISTS Statements
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045135927520">
  </a>
  <a class="indexterm" name="idm46045135926016">
  </a>
  <p>
   MySQL applies these rules when various
   <code class="literal">
    CREATE ... IF
        NOT EXISTS
   </code>
   statements are replicated:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Every
      <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
       <code class="literal">
        CREATE
            DATABASE IF NOT EXISTS
       </code>
      </a>
      statement is replicated,
            whether or not the database already exists on the source.
     </p>
    </li>
    <li class="listitem">
     <p>
      Similarly, every
      <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       <code class="literal">
        CREATE TABLE
            IF NOT EXISTS
       </code>
      </a>
      statement without a
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      is replicated, whether
            or not the table already exists on the source. This includes
      <a class="link" href="create-table-like.html" title="15.1.20.3 CREATE TABLE ... LIKE Statement">
       <code class="literal">
        CREATE
            TABLE IF NOT EXISTS ... LIKE
       </code>
      </a>
      . Replication of
      <a class="link" href="create-table-select.html" title="15.1.20.4 CREATE TABLE ... SELECT Statement">
       <code class="literal">
        CREATE
            TABLE IF NOT EXISTS ... SELECT
       </code>
      </a>
      follows somewhat
            different rules; see
      <a class="xref" href="replication-features-create-select.html" title="19.5.1.7 Replication of CREATE TABLE ... SELECT Statements">
       Section 19.5.1.7, “Replication of CREATE TABLE ... SELECT Statements”
      </a>
      , for
            more information.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="create-event.html" title="15.1.13 CREATE EVENT Statement">
       <code class="literal">
        CREATE EVENT
            IF NOT EXISTS
       </code>
      </a>
      is always replicated, whether or not
            the event named in the statement already exists on the
            source.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement">
       <code class="literal">
        CREATE USER
       </code>
      </a>
      is written to the
            binary log only if successful. If the statement includes
      <code class="literal">
       IF NOT EXISTS
      </code>
      , it is considered
            successful, and is logged as long as at least one user named
            in the statement is created; in such cases, the statement is
            logged as written; this includes references to existing
            users that were not created. See
      <a class="xref" href="create-user.html#create-user-binary-logging" title="CREATE USER Binary Logging">
       CREATE USER Binary Logging
      </a>
      , for more
            information.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="create-procedure.html" title="15.1.17 CREATE PROCEDURE and CREATE FUNCTION Statements">
       <code class="literal">
        CREATE
            PROCEDURE IF NOT EXISTS
       </code>
      </a>
      ,
      <a class="link" href="create-function.html" title="15.1.14 CREATE FUNCTION Statement">
       <code class="literal">
        CREATE
            FUNCTION IF NOT EXISTS
       </code>
      </a>
      , or
      <a class="link" href="create-trigger.html" title="15.1.22 CREATE TRIGGER Statement">
       <code class="literal">
        CREATE
            TRIGGER IF NOT EXISTS
       </code>
      </a>
      , if successful, is written
            in its entirety to the binary log (including the
      <code class="literal">
       IF
            NOT EXISTS
      </code>
      clause), whether or not the statement
            raised a warning because the object (procedure, function, or
            trigger) already existed.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
