<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="reset-binary-logs-and-gtids">
      </a>
      15.4.1.2 RESET BINARY LOGS AND GTIDS Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045177855152">
  </a>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    This statement takes the place of the old
    <code class="literal">
     RESET
          MASTER
    </code>
    statement, which is no longer supported.
   </p>
  </div>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa89060994"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">RESET</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span> <span class="token operator">AND</span> GTIDS <span class="token punctuation">[</span><span class="token keyword">TO</span> <em class="replaceable">binary_log_file_index_number</em><span class="token punctuation">]</span></code></pre>
  </div>
  <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Warning
   </div>
   <p>
    Use this statement with caution to ensure you do not lose any
          wanted binary log file data and GTID execution history.
   </p>
  </div>
  <p>
   <code class="literal">
    RESET BINARY LOGS AND GTIDS
   </code>
   requires the
   <a class="link" href="privileges-provided.html#priv_reload">
    <code class="literal">
     RELOAD
    </code>
   </a>
   privilege.
  </p>
  <p>
   For a server where binary logging is enabled
        (
   <a class="link" href="replication-options-binary-log.html#sysvar_log_bin">
    <code class="literal">
     log_bin
    </code>
   </a>
   is
   <code class="literal">
    ON
   </code>
   ),
   <code class="literal">
    RESET BINARY LOGS AND
        GTIDS
   </code>
   deletes all existing binary log files and resets
        the binary log index file, resetting the server to its state
        before binary logging was started. A new empty binary log file
        is created so that binary logging can be restarted.
  </p>
  <p>
   For a server where GTIDs are in use
        (
   <a class="link" href="replication-options-gtids.html#sysvar_gtid_mode">
    <code class="literal">
     gtid_mode
    </code>
   </a>
   is
   <code class="literal">
    ON
   </code>
   ), issuing
   <code class="literal">
    RESET BINARY LOGS AND
        GTIDS
   </code>
   resets the GTID execution history. The value of
        the
   <a class="link" href="replication-options-gtids.html#sysvar_gtid_purged">
    <code class="literal">
     gtid_purged
    </code>
   </a>
   system variable
        is set to an empty string (
   <code class="literal">
    ''
   </code>
   ), the global
        value (but not the session value) of the
   <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed">
    <code class="literal">
     gtid_executed
    </code>
   </a>
   system variable
        is set to an empty string, and the
   <code class="literal">
    mysql.gtid_executed
   </code>
   table is cleared (see
   <a class="xref" href="replication-gtids-concepts.html#replication-gtids-gtid-executed-table" title="mysql.gtid_executed Table">
    mysql.gtid_executed Table
   </a>
   ). If the
        GTID-enabled server has binary logging enabled,
   <code class="literal">
    RESET
        BINARY LOGS AND GTIDS
   </code>
   also resets the binary log as
        described above. Note that
   <code class="literal">
    RESET BINARY LOGS AND
        GTIDS
   </code>
   is the method to reset the GTID execution
        history even if the GTID-enabled server is a replica where
        binary logging is disabled;
   <a class="link" href="reset-replica.html" title="15.4.2.3 RESET REPLICA Statement">
    <code class="literal">
     RESET
        REPLICA
    </code>
   </a>
   has no effect on the GTID execution history.
        For more information on resetting the GTID execution history,
        see
   <a class="xref" href="replication-gtids-lifecycle.html#replication-gtids-execution-history" title="Resetting the GTID Execution History">
    Resetting the GTID Execution History
   </a>
   .
  </p>
  <p>
   Issuing
   <code class="literal">
    RESET BINARY LOGS AND GTIDS
   </code>
   without
        the optional
   <code class="literal">
    TO
   </code>
   clause deletes all binary log
        files listed in the index file, resets the binary log index file
        to be empty, and creates a new binary log file starting at
   <code class="literal">
    1
   </code>
   . Use the optional
   <code class="literal">
    TO
   </code>
   clause to start the binary log file index from a number other
        than
   <code class="literal">
    1
   </code>
   after the reset.
  </p>
  <p>
   Check that you are using a reasonable value for the index
        number. If you enter an incorrect value, you can correct this by
        issuing another
   <code class="literal">
    RESET BINARY LOGS AND GTIDS
   </code>
   statement with or without the
   <code class="literal">
    TO
   </code>
   clause. If
        you do not correct a value that is out of range, the server
        cannot be restarted.
  </p>
  <p>
   The following example demonstrates
   <code class="literal">
    TO
   </code>
   clause
        usage:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa74476384"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">RESET</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span> <span class="token operator">AND</span> GTIDS <span class="token keyword">TO</span> <span class="token number">1234</span><span class="token punctuation">;</span>

<span class="token keyword">SHOW</span> <span class="token datatype">BINARY</span> <span class="token keyword">LOGS</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Log_name          <span class="token punctuation">|</span> File_size <span class="token punctuation">|</span> Encrypted <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> source<span class="token punctuation">-</span>bin.001234 <span class="token punctuation">|</span>       154 <span class="token punctuation">|</span> No        <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
  </div>
  <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Important
   </div>
   <p>
    The effects of
    <code class="literal">
     RESET BINARY LOGS AND GTIDS
    </code>
    without the
    <code class="literal">
     TO
    </code>
    clause differ from those of
    <a class="link" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement">
     <code class="literal">
      PURGE BINARY LOGS
     </code>
    </a>
    in 2 key
          ways:
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       <code class="literal">
        RESET BINARY LOGS AND GTIDS
       </code>
       removes
       <span class="emphasis">
        <em>
         all
        </em>
       </span>
       binary log files that are listed
              in the index file, leaving only a single, empty binary log
              file with a numeric suffix of
       <code class="literal">
        .000001
       </code>
       ,
              whereas the numbering is not reset by
       <a class="link" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement">
        <code class="literal">
         PURGE BINARY LOGS
        </code>
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       <code class="literal">
        RESET BINARY LOGS AND GTIDS
       </code>
       is
       <span class="emphasis">
        <em>
         not
        </em>
       </span>
       intended to be used while any
              replicas are running. The behavior of
       <code class="literal">
        RESET
              BINARY LOGS AND GTIDS
       </code>
       when used while replicas
              are running is undefined (and thus unsupported), whereas
       <a class="link" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement">
        <code class="literal">
         PURGE BINARY LOGS
        </code>
       </a>
       may be
              safely used while replicas are running.
      </p>
     </li>
    </ol>
   </div>
   <p>
    See also
    <a class="xref" href="purge-binary-logs.html" title="15.4.1.1 PURGE BINARY LOGS Statement">
     Section 15.4.1.1, “PURGE BINARY LOGS Statement”
    </a>
    .
   </p>
  </div>
  <p>
   <code class="literal">
    RESET BINARY LOGS AND GTIDS
   </code>
   without the
   <code class="literal">
    TO
   </code>
   clause can prove useful when you first set
        up a source and replica, so that you can verify the setup as
        follows:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Start the source and replica, and start replication (see
      <a class="xref" href="replication-howto.html" title="19.1.2 Setting Up Binary Log File Position Based Replication">
       Section 19.1.2, “Setting Up Binary Log File Position Based Replication”
      </a>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      Execute a few test queries on the source.
     </p>
    </li>
    <li class="listitem">
     <p>
      Check that the queries were replicated to the replica.
     </p>
    </li>
    <li class="listitem">
     <p>
      When replication is running correctly, issue
      <a class="link" href="stop-replica.html" title="15.4.2.5 STOP REPLICA Statement">
       <code class="literal">
        STOP REPLICA
       </code>
      </a>
      followed by
      <a class="link" href="reset-replica.html" title="15.4.2.3 RESET REPLICA Statement">
       <code class="literal">
        RESET REPLICA
       </code>
      </a>
      (both on the
            replica), then verify that no unwanted data from the test
            queries exists on the replica. Following this, issue
      <code class="literal">
       RESET BINARY LOGS AND GTIDS
      </code>
      (also on the
            replica) to remove binary logs and and associated
            transaction IDs.
     </p>
    </li>
    <li class="listitem">
     <p>
      Remove the unwanted data from the source, then issue
      <code class="literal">
       RESET BINARY LOGS AND GTIDS
      </code>
      to purge any
            binary log entries and identifiers associated with it.
     </p>
    </li>
   </ol>
  </div>
  <p>
   After verifying the setup, resetting the source and replica and
        ensuring that no unwanted data or binary log files generated by
        testing remain on the source or replica, you can start the
        replica and begin replicating.
  </p>
 </div>
 <br/>
</div>
