<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="replication-rules-db-options">
      </a>
      19.2.5.1 Evaluation of Database-Level Replication and Binary Logging Options
     </h4>
    </div>
   </div>
  </div>
  <p>
   When evaluating replication options, the replica begins by
        checking to see whether there are any
   <a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-db">
    <code class="option">
     --replicate-do-db
    </code>
   </a>
   or
   <a class="link" href="replication-options-replica.html#option_mysqld_replicate-ignore-db">
    <code class="option">
     --replicate-ignore-db
    </code>
   </a>
   options
        that apply. When using
   <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db">
    <code class="option">
     --binlog-do-db
    </code>
   </a>
   or
   <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db">
    <code class="option">
     --binlog-ignore-db
    </code>
   </a>
   , the process
        is similar, but the options are checked on the source.
  </p>
  <p>
   The database that is checked for a match depends on the binary
        log format of the statement that is being handled. If the
        statement has been logged using the row format, the database
        where data is to be changed is the database that is checked. If
        the statement has been logged using the statement format, the
        default database (specified with a
   <a class="link" href="use.html" title="15.8.4 USE Statement">
    <code class="literal">
     USE
    </code>
   </a>
   statement) is the database
        that is checked.
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    Only DML statements can be logged using the row format. DDL
          statements are always logged as statements, even when
    <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format">
     <code class="literal">
      binlog_format=ROW
     </code>
    </a>
    . All DDL
          statements are therefore always filtered according to the
          rules for statement-based replication. This means that you
          must select the default database explicitly with a
    <a class="link" href="use.html" title="15.8.4 USE Statement">
     <code class="literal">
      USE
     </code>
    </a>
    statement in order for a
          DDL statement to be applied.
   </p>
  </div>
  <p>
   For replication, the steps involved are listed here:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Which logging format is used?
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         <b>
          STATEMENT.
         </b>
         Test the default database.
        </p>
       </li>
       <li class="listitem">
        <p>
         <b>
          ROW.
         </b>
         Test the database affected by the changes.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      Are there any
      <a class="link" href="replication-options-replica.html#option_mysqld_replicate-do-db">
       <code class="option">
        --replicate-do-db
       </code>
      </a>
      options?
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         <b>
          Yes.
         </b>
         Does the database match any of them?
        </p>
        <div class="itemizedlist">
         <ul class="itemizedlist" style="list-style-type: circle; ">
          <li class="listitem">
           <p>
            <b>
             Yes.
            </b>
            Continue to Step 4.
           </p>
          </li>
          <li class="listitem">
           <p>
            <b>
             No.
            </b>
            Ignore the update and exit.
           </p>
          </li>
         </ul>
        </div>
        <p>
        </p>
       </li>
       <li class="listitem">
        <p>
         <b>
          No.
         </b>
         Continue to step 3.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      Are there any
      <a class="link" href="replication-options-replica.html#option_mysqld_replicate-ignore-db">
       <code class="option">
        --replicate-ignore-db
       </code>
      </a>
      options?
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         <b>
          Yes.
         </b>
         Does the database match any of them?
        </p>
        <div class="itemizedlist">
         <ul class="itemizedlist" style="list-style-type: circle; ">
          <li class="listitem">
           <p>
            <b>
             Yes.
            </b>
            Ignore the update and exit.
           </p>
          </li>
          <li class="listitem">
           <p>
            <b>
             No.
            </b>
            Continue to step 4.
           </p>
          </li>
         </ul>
        </div>
        <p>
        </p>
       </li>
       <li class="listitem">
        <p>
         <b>
          No.
         </b>
         Continue to step 4.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      Proceed to checking the table-level replication options, if
            there are any. For a description of how these options are
            checked, see
      <a class="xref" href="replication-rules-table-options.html" title="19.2.5.2 Evaluation of Table-Level Replication Options">
       Section 19.2.5.2, “Evaluation of Table-Level Replication Options”
      </a>
      .
     </p>
     <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Important
      </div>
      <p>
       A statement that is still permitted at this stage is not
              yet actually executed. The statement is not executed until
              all table-level options (if any) have also been checked,
              and the outcome of that process permits execution of the
              statement.
      </p>
     </div>
    </li>
   </ol>
  </div>
  <p>
   For binary logging, the steps involved are listed here:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Are there any
      <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db">
       <code class="option">
        --binlog-do-db
       </code>
      </a>
      or
      <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db">
       <code class="option">
        --binlog-ignore-db
       </code>
      </a>
      options?
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         <b>
          Yes.
         </b>
         Continue to step 2.
        </p>
       </li>
       <li class="listitem">
        <p>
         <b>
          No.
         </b>
         Log the statement and exit.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      Is there a default database (has any database been selected
            by
      <a class="link" href="use.html" title="15.8.4 USE Statement">
       <code class="literal">
        USE
       </code>
      </a>
      )?
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         <b>
          Yes.
         </b>
         Continue to step 3.
        </p>
       </li>
       <li class="listitem">
        <p>
         <b>
          No.
         </b>
         Ignore the statement and exit.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      There is a default database. Are there any
      <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db">
       <code class="option">
        --binlog-do-db
       </code>
      </a>
      options?
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         <b>
          Yes.
         </b>
         Do any of them match the database?
        </p>
        <div class="itemizedlist">
         <ul class="itemizedlist" style="list-style-type: circle; ">
          <li class="listitem">
           <p>
            <b>
             Yes.
            </b>
            Log the statement and exit.
           </p>
          </li>
          <li class="listitem">
           <p>
            <b>
             No.
            </b>
            Ignore the statement and exit.
           </p>
          </li>
         </ul>
        </div>
        <p>
        </p>
       </li>
       <li class="listitem">
        <p>
         <b>
          No.
         </b>
         Continue to step 4.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      Do any of the
      <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-ignore-db">
       <code class="option">
        --binlog-ignore-db
       </code>
      </a>
      options
            match the database?
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         <b>
          Yes.
         </b>
         Ignore the statement and exit.
        </p>
       </li>
       <li class="listitem">
        <p>
         <b>
          No.
         </b>
         Log the statement and exit.
        </p>
       </li>
      </ul>
     </div>
    </li>
   </ol>
  </div>
  <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Important
   </div>
   <p>
    For statement-based logging, an exception is made in the rules
          just given for the
    <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
     <code class="literal">
      CREATE
          DATABASE
     </code>
    </a>
    ,
    <a class="link" href="alter-database.html" title="15.1.2 ALTER DATABASE Statement">
     <code class="literal">
      ALTER
          DATABASE
     </code>
    </a>
    , and
    <a class="link" href="drop-database.html" title="15.1.24 DROP DATABASE Statement">
     <code class="literal">
      DROP
          DATABASE
     </code>
    </a>
    statements. In those cases, the database
          being
    <span class="emphasis">
     <em>
      created, altered, or dropped
     </em>
    </span>
    replaces the default database when determining whether to log
          or ignore updates.
   </p>
  </div>
  <p>
   <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db">
    <code class="option">
     --binlog-do-db
    </code>
   </a>
   can sometimes mean
   <span class="quote">
    “
    <span class="quote">
     ignore other databases
    </span>
    ”
   </span>
   . For example, when using
        statement-based logging, a server running with only
   <a class="link" href="replication-options-binary-log.html#option_mysqld_binlog-do-db">
    <code class="option">
     --binlog-do-db=sales
    </code>
   </a>
   does not
        write to the binary log statements for which the default
        database differs from
   <code class="literal">
    sales
   </code>
   . When using
        row-based logging with the same option, the server logs only
        those updates that change data in
   <code class="literal">
    sales
   </code>
   .
  </p>
 </div>
 <br/>
</div>
