<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="set-sql-log-bin">
      </a>
      15.4.1.3 SET sql_log_bin Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045177793296">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa67996332"><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">SET</span> sql_log_bin <span class="token operator">=</span> {<span class="token keyword">OFF</span><span class="token operator">|</span><span class="token keyword">ON</span>}</code></pre>
  </div>
  <p>
   The
   <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin">
    <code class="literal">
     sql_log_bin
    </code>
   </a>
   variable
        controls whether logging to the binary log is enabled for the
        current session (assuming that the binary log itself is
        enabled). The default value is
   <code class="literal">
    ON
   </code>
   . To disable
        or enable binary logging for the current session, set the
        session
   <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin">
    <code class="literal">
     sql_log_bin
    </code>
   </a>
   variable to
   <code class="literal">
    OFF
   </code>
   or
   <code class="literal">
    ON
   </code>
   .
  </p>
  <p>
   Set this variable to
   <code class="literal">
    OFF
   </code>
   for a session to
        temporarily disable binary logging while making changes to the
        source that you do not want replicated to the replica.
  </p>
  <p>
   Setting the session value of this system variable is a
        restricted operation. The session user must have privileges
        sufficient to set restricted session variables. See
   <a class="xref" href="system-variable-privileges.html" title="7.1.9.1 System Variable Privileges">
    Section 7.1.9.1, “System Variable Privileges”
   </a>
   .
  </p>
  <p>
   It is not possible to set the session value of
   <a class="link" href="replication-options-binary-log.html#sysvar_sql_log_bin">
    <code class="literal">
     sql_log_bin
    </code>
   </a>
   within a
        transaction or subquery.
  </p>
  <p>
   <span class="emphasis">
    <em>
     Setting this variable to
     <code class="literal">
      OFF
     </code>
     prevents new GTIDs from being assigned to transactions in the
        binary log
    </em>
   </span>
   . If you are using GTIDs for replication,
        this means that even when binary logging is later enabled again,
        the GTIDs written into the log from this point do not account
        for any transactions that occurred in the meantime, so in effect
        those transactions are lost.
  </p>
  <p>
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   adds a
   <code class="literal">
    SET
        @@SESSION.sql_log_bin=0
   </code>
   statement to a dump file from
        a server where GTIDs are in use, which disables binary logging
        while the dump file is being reloaded. The statement prevents
        new GTIDs from being generated and assigned to the transactions
        in the dump file as they are executed, so that the original
        GTIDs for the transactions are used.
  </p>
 </div>
 <br/>
</div>
