<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="lock-instance-for-backup">
      </a>
      15.3.5 LOCK INSTANCE FOR BACKUP and UNLOCK INSTANCE Statements
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045178594144">
  </a>
  <a class="indexterm" name="idm46045178593104">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa54857345"><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">LOCK</span> <span class="token keyword">INSTANCE</span> <span class="token keyword">FOR</span> <span class="token keyword">BACKUP</span>

<span class="token keyword">UNLOCK</span> <span class="token keyword">INSTANCE</span></code></pre>
  </div>
  <p>
   <code class="literal">
    LOCK INSTANCE FOR BACKUP
   </code>
   acquires an
      instance-level
   <span class="emphasis">
    <em>
     backup lock
    </em>
   </span>
   that permits DML
      during an online backup while preventing operations that could
      result in an inconsistent snapshot.
  </p>
  <p>
   Executing the
   <code class="literal">
    LOCK INSTANCE FOR BACKUP
   </code>
   statement requires the
   <a class="link" href="privileges-provided.html#priv_backup-admin">
    <code class="literal">
     BACKUP_ADMIN
    </code>
   </a>
   privilege. The
   <a class="link" href="privileges-provided.html#priv_backup-admin">
    <code class="literal">
     BACKUP_ADMIN
    </code>
   </a>
   privilege is automatically granted to users with the
   <a class="link" href="privileges-provided.html#priv_reload">
    <code class="literal">
     RELOAD
    </code>
   </a>
   privilege when performing an
      in-place upgrade to MySQL 8.4 from an earlier
      version.
  </p>
  <p>
   Multiple sessions can hold a backup lock simultaneously.
  </p>
  <p>
   <code class="literal">
    UNLOCK INSTANCE
   </code>
   releases a backup lock held by
      the current session. A backup lock held by a session is also
      released if the session is terminated.
  </p>
  <p>
   <code class="literal">
    LOCK INSTANCE FOR BACKUP
   </code>
   prevents files from
      being created, renamed, or removed.
   <a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement">
    <code class="literal">
     REPAIR
      TABLE
    </code>
   </a>
   <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement">
    <code class="literal">
     TRUNCATE TABLE
    </code>
   </a>
   ,
   <a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
    <code class="literal">
     OPTIMIZE TABLE
    </code>
   </a>
   , and account
      management statements are blocked. See
   <a class="xref" href="account-management-statements.html" title="15.7.1 Account Management Statements">
    Section 15.7.1, “Account Management Statements”
   </a>
   . Operations that
      modify
   <code class="literal">
    InnoDB
   </code>
   files that are not recorded in
      the
   <code class="literal">
    InnoDB
   </code>
   redo log are also blocked.
  </p>
  <p>
   <code class="literal">
    LOCK INSTANCE FOR BACKUP
   </code>
   permits DDL operations
      that only affect user-created temporary tables. In effect, files
      that belong to user-created temporary tables can be created,
      renamed, or removed while a backup lock is held. Creation of
      binary log files is also permitted.
  </p>
  <p>
   <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>
   cannot be issued
      while a
   <a class="link" href="lock-instance-for-backup.html" title="15.3.5 LOCK INSTANCE FOR BACKUP and UNLOCK INSTANCE Statements">
    <code class="literal">
     LOCK INSTANCE FOR BACKUP
    </code>
   </a>
   statement is in effect for the instance, because it contravenes
      the rules of the backup lock by removing files from the server.
  </p>
  <p>
   A backup lock acquired by
   <code class="literal">
    LOCK INSTANCE FOR
      BACKUP
   </code>
   is independent of transactional locks and locks
      taken by
   <a class="link" href="flush.html#flush-tables-with-read-lock-with-list">
    <code class="literal">
     FLUSH
      TABLES
     <em class="replaceable">
      <code>
       tbl_name
      </code>
     </em>
     [,
     <em class="replaceable">
      <code>
       tbl_name
      </code>
     </em>
     ] ... WITH READ LOCK
    </code>
   </a>
   ,
      and the following sequences of statements are permitted:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa88799364"><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">LOCK</span> <span class="token keyword">INSTANCE</span> <span class="token keyword">FOR</span> <span class="token keyword">BACKUP</span><span class="token punctuation">;</span>
<span class="token keyword">FLUSH</span> <span class="token keyword">TABLES</span> <em class="replaceable">tbl_name</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">tbl_name</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">WITH</span> <span class="token keyword">READ</span> <span class="token keyword">LOCK</span><span class="token punctuation">;</span>
<span class="token keyword">UNLOCK</span> <span class="token keyword">TABLES</span><span class="token punctuation">;</span>
<span class="token keyword">UNLOCK</span> <span class="token keyword">INSTANCE</span><span class="token punctuation">;</span></code></pre>
  </div>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24319236"><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">FLUSH</span> <span class="token keyword">TABLES</span> <em class="replaceable">tbl_name</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">tbl_name</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">WITH</span> <span class="token keyword">READ</span> <span class="token keyword">LOCK</span><span class="token punctuation">;</span>
<span class="token keyword">LOCK</span> <span class="token keyword">INSTANCE</span> <span class="token keyword">FOR</span> <span class="token keyword">BACKUP</span><span class="token punctuation">;</span>
<span class="token keyword">UNLOCK</span> <span class="token keyword">INSTANCE</span><span class="token punctuation">;</span>
<span class="token keyword">UNLOCK</span> <span class="token keyword">TABLES</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The
   <a class="link" href="server-system-variables.html#sysvar_lock_wait_timeout">
    <code class="literal">
     lock_wait_timeout
    </code>
   </a>
   setting
      defines the amount of time that a
   <code class="literal">
    LOCK INSTANCE FOR
      BACKUP
   </code>
   statement waits to acquire a lock before giving
      up.
  </p>
 </div>
 <br/>
</div>
