<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="stop-replica">
      </a>
      15.4.2.5 STOP REPLICA Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045176922928">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa88269947"><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">STOP</span> <span class="token keyword">REPLICA</span> <span class="token punctuation">[</span><em class="replaceable">thread_types</em><span class="token punctuation">]</span> <span class="token punctuation">[</span><em class="replaceable">channel_option</em><span class="token punctuation">]</span>

<em class="replaceable">thread_types</em>:
    <span class="token punctuation">[</span><em class="replaceable">thread_type</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">thread_type</em><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>

<em class="replaceable">thread_type</em>: <span class="token keyword">IO_THREAD</span> <span class="token operator">|</span> <span class="token keyword">SQL_THREAD</span>

<em class="replaceable">channel_option</em>:
    <span class="token keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token keyword"><em class="replaceable">channel</em></span></code></pre>
  </div>
  <p>
   Stops the replication threads.
  </p>
  <p>
   <code class="literal">
    STOP REPLICA
   </code>
   requires the
   <a class="link" href="privileges-provided.html#priv_replication-slave-admin">
    <code class="literal">
     REPLICATION_SLAVE_ADMIN
    </code>
   </a>
   privilege
        (or the deprecated
   <a class="link" href="privileges-provided.html#priv_super">
    <code class="literal">
     SUPER
    </code>
   </a>
   privilege). Recommended best practice is to execute
   <code class="literal">
    STOP REPLICA
   </code>
   on the replica before stopping
        the replica server (see
   <a class="xref" href="server-shutdown.html" title="7.1.19 The Server Shutdown Process">
    Section 7.1.19, “The Server Shutdown Process”
   </a>
   , for
        more information).
  </p>
  <p>
   Like
   <a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
    <code class="literal">
     START REPLICA
    </code>
   </a>
   , this
        statement may be used with the
   <code class="literal">
    IO_THREAD
   </code>
   and
   <code class="literal">
    SQL_THREAD
   </code>
   options to name the replication
        thread or threads to be stopped. Note that the Group Replication
        applier channel (
   <code class="literal">
    group_replication_applier
   </code>
   )
        has no replication I/O (receiver) thread, only a replication SQL
        (applier) thread. Using the
   <code class="literal">
    SQL_THREAD
   </code>
   option
        therefore stops this channel completely.
  </p>
  <p>
   <code class="literal">
    STOP REPLICA
   </code>
   causes an implicit commit of an
        ongoing transaction. See
   <a class="xref" href="implicit-commit.html" title="15.3.3 Statements That Cause an Implicit Commit">
    Section 15.3.3, “Statements That Cause an Implicit Commit”
   </a>
   .
  </p>
  <p>
   <a class="link" href="replication-options-gtids.html#sysvar_gtid_next">
    <code class="literal">
     gtid_next
    </code>
   </a>
   must be set to
   <code class="literal">
    AUTOMATIC
   </code>
   before issuing this statement.
  </p>
  <p>
   You can control how long
   <code class="literal">
    STOP REPLICA
   </code>
   waits
        before timing out by setting the system variable
   <a class="link" href="replication-options-replica.html#sysvar_rpl_stop_replica_timeout">
    <code class="literal">
     rpl_stop_replica_timeout
    </code>
   </a>
   . This
        can be used to avoid deadlocks between
   <code class="literal">
    STOP
        REPLICA
   </code>
   and other SQL statements using different
        client connections to the replica. When the timeout value is
        reached, the issuing client returns an error message and stops
        waiting, but the
   <code class="literal">
    STOP REPLICA
   </code>
   instruction
        remains in effect. Once the replication threads are no longer
        busy, the
   <code class="literal">
    STOP REPLICA
   </code>
   statement is executed
        and the replica stops.
  </p>
  <p>
   Some
   <a class="link" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement">
    <code class="literal">
     CHANGE REPLICATION SOURCE TO
    </code>
   </a>
   statements are allowed while the replica is running, depending
        on the states of the replication threads. However, using
   <code class="literal">
    STOP REPLICA
   </code>
   prior to executing a
   <a class="link" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement">
    <code class="literal">
     CHANGE REPLICATION SOURCE TO
    </code>
   </a>
   statement in such cases is still supported. See
   <a class="xref" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement">
    Section 15.4.2.2, “CHANGE REPLICATION SOURCE TO Statement”
   </a>
   , and
   <a class="xref" href="replication-solutions-switch.html" title="19.4.8 Switching Sources During Failover">
    Section 19.4.8, “Switching Sources During Failover”
   </a>
   , for more
        information.
  </p>
  <p>
   The optional
   <code class="literal">
    FOR CHANNEL
    <em class="replaceable">
     <code>
      channel
     </code>
    </em>
   </code>
   clause enables you
        to name which replication channel the statement applies to.
        Providing a
   <code class="literal">
    FOR CHANNEL
    <em class="replaceable">
     <code>
      channel
     </code>
    </em>
   </code>
   clause applies the
   <code class="literal">
    STOP REPLICA
   </code>
   statement to a specific
        replication channel. If no channel is named and no extra
        channels exist, the statement applies to the default channel. If
        a
   <code class="literal">
    STOP REPLICA
   </code>
   statement does not name a
        channel when using multiple channels, this statement stops the
        specified threads for all channels. See
   <a class="xref" href="replication-channels.html" title="19.2.2 Replication Channels">
    Section 19.2.2, “Replication Channels”
   </a>
   for more
        information.
  </p>
  <p>
   The replication channels for Group Replication
        (
   <code class="literal">
    group_replication_applier
   </code>
   and
   <code class="literal">
    group_replication_recovery
   </code>
   ) are managed
        automatically by the server instance.
   <code class="literal">
    STOP
        REPLICA
   </code>
   cannot be used at all with the
   <code class="literal">
    group_replication_recovery
   </code>
   channel, and
        should only be used with the
   <code class="literal">
    group_replication_applier
   </code>
   channel when Group
        Replication is not running. The
   <code class="literal">
    group_replication_applier
   </code>
   channel only has an
        applier thread and has no receiver thread, so it can be stopped
        if required by using the
   <code class="literal">
    SQL_THREAD
   </code>
   option
        without the
   <code class="literal">
    IO_THREAD
   </code>
   option.
  </p>
  <p>
   When the replica is multithreaded
        (
   <a class="link" href="replication-options-replica.html#sysvar_replica_parallel_workers">
    <code class="literal">
     replica_parallel_workers
    </code>
   </a>
   is a
        nonzero value), any gaps in the sequence of transactions
        executed from the relay log are closed as part of stopping the
        worker threads. If the replica is stopped unexpectedly (for
        example due to an error in a worker thread, or another thread
        issuing
   <a class="link" href="kill.html" title="15.7.8.4 KILL Statement">
    <code class="literal">
     KILL
    </code>
   </a>
   ) while a
   <code class="literal">
    STOP REPLICA
   </code>
   statement is executing, the
        sequence of executed transactions from the relay log may become
        inconsistent. See
   <a class="xref" href="replication-features-transaction-inconsistencies.html" title="19.5.1.34 Replication and Transaction Inconsistencies">
    Section 19.5.1.34, “Replication and Transaction Inconsistencies”
   </a>
   ,
        for more information.
  </p>
  <p>
   When the source is using the row-based binary logging format,
        you should execute
   <code class="literal">
    STOP REPLICA
   </code>
   or
   <code class="literal">
    STOP REPLICA SQL_THREAD
   </code>
   on the replica prior
        to shutting down the replica server if you are replicating any
        tables that use a nontransactional storage engine. If the
        current replication event group has modified one or more
        nontransactional tables,
   <code class="literal">
    STOP REPLICA
   </code>
   waits
        for up to 60 seconds for the event group to complete, unless you
        issue a
   <a class="link" href="kill.html" title="15.7.8.4 KILL Statement">
    <code class="literal">
     KILL
        QUERY
    </code>
   </a>
   or
   <a class="link" href="kill.html" title="15.7.8.4 KILL Statement">
    <code class="literal">
     KILL
        CONNECTION
    </code>
   </a>
   statement for the replication SQL thread.
        If the event group remains incomplete after the timeout, an
        error message is logged.
  </p>
  <p>
   When the source is using the statement-based binary logging
        format, changing the source while it has open temporary tables
        is potentially unsafe. This is one of the reasons why
        statement-based replication of temporary tables is not
        recommended. You can find out whether there are any temporary
        tables on the replica by checking the value of
   <a class="link" href="server-status-variables.html#statvar_Replica_open_temp_tables">
    <code class="literal">
     Replica_open_temp_tables
    </code>
   </a>
   . When
        using statement-based replication, this value should be 0 before
        executing
   <a class="link" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement">
    <code class="literal">
     CHANGE REPLICATION SOURCE
        TO
    </code>
   </a>
   . If there are any temporary tables open on the
        replica, issuing a
   <a class="link" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement">
    <code class="literal">
     CHANGE REPLICATION
        SOURCE TO
    </code>
   </a>
   statement after issuing a
   <code class="literal">
    STOP
        REPLICA
   </code>
   causes an
   <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_warn_open_temp_tables_must_be_zero" target="_top">
    <code class="literal">
     ER_WARN_OPEN_TEMP_TABLES_MUST_BE_ZERO
    </code>
   </a>
   warning.
  </p>
 </div>
 <br/>
</div>
