<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="clone-plugin-replication">
      </a>
      7.6.7.7 Cloning for Replication
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045255402416">
  </a>
  <p>
   The clone plugin supports replication. In addition to cloning
        data, a cloning operation extracts replication coordinates from
        the donor and transfers them to the recipient, which enables
        using the clone plugin for provisioning Group Replication
        members and replicas. Using the clone plugin for provisioning is
        considerably faster and more efficient than replicating a large
        number of transactions.
  </p>
  <p>
   Group Replication members can also be configured to use the
        clone plugin as an option for distributed recovery, in which
        case joining members automatically choose the most efficient way
        to retrieve group data from existing group members. For more
        information, see
   <a class="xref" href="group-replication-cloning.html" title="20.5.4.2 Cloning for Distributed Recovery">
    Section 20.5.4.2, “Cloning for Distributed Recovery”
   </a>
   .
  </p>
  <p>
   During the cloning operation, both the binary log position
        (filename, offset) and the
   <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed">
    <code class="literal">
     gtid_executed
    </code>
   </a>
   GTID set are
        extracted and transferred from the donor MySQL server instance
        to the recipient. This data permits initiating replication at a
        consistent position in the replication stream. The binary logs
        and relay logs, which are held in files, are not copied from the
        donor to the recipient. To initiate replication, the binary logs
        required for the recipient to catch up to the donor must not be
        purged between the time that the data is cloned and the time
        that replication is started. If the required binary logs are not
        available, a replication handshake error is reported. A cloned
        instance should therefore be added to a replication group
        without excessive delay to avoid required binary logs being
        purged or the new member lagging behind significantly, requiring
        more recovery time.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Issue this query on a cloned MySQL server instance to check
            the binary log position that was transferred to the
            recipient:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa70593575"><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 prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> BINLOG_FILE<span class="token punctuation">,</span> BINLOG_POSITION <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>clone_status<span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Issue this query on a cloned MySQL server instance to check
            the
      <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed">
       <code class="literal">
        gtid_executed
       </code>
      </a>
      GTID set
            that was transferred to the recipient:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa74185098"><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 prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token variable">@@GLOBAL.GTID_EXECUTED</span><span class="token punctuation">;</span></code></pre>
     </div>
    </li>
   </ul>
  </div>
  <p>
   By default, the replication metadata repositories are held in
        tables that are copied from the donor to the recipient during
        the cloning operation. The replication metadata repositories
        hold replication-related configuration settings that can be used
        to resume replication correctly after the cloning operation. The
        tables
   <code class="literal">
    mysql.slave_master_info
   </code>
   ,
   <code class="literal">
    mysql.slave_relay_log_info
   </code>
   , and
   <code class="literal">
    mysql.slave_worker_info
   </code>
   are all copied.
  </p>
  <p>
   For a list of what is included in each table, see
   <a class="xref" href="replica-logs-status.html" title="19.2.4.2 Replication Metadata Repositories">
    Section 19.2.4.2, “Replication Metadata Repositories”
   </a>
   .
  </p>
  <p>
   To clone for replication, perform the following steps:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      For a new group member for Group Replication, first
            configure the MySQL Server instance for Group Replication,
            following the instructions in
      <a class="xref" href="group-replication-adding-instances.html" title="20.2.1.6 Adding Instances to the Group">
       Section 20.2.1.6, “Adding Instances to the Group”
      </a>
      . Also
            set up the prerequisites for cloning described in
      <a class="xref" href="group-replication-cloning.html" title="20.5.4.2 Cloning for Distributed Recovery">
       Section 20.5.4.2, “Cloning for Distributed Recovery”
      </a>
      . When you issue
      <a class="link" href="start-group-replication.html" title="15.4.3.1 START GROUP_REPLICATION Statement">
       <code class="literal">
        START GROUP_REPLICATION
       </code>
      </a>
      on
            the joining member, the cloning operation is managed
            automatically by Group Replication, so you do not need to
            carry out the operation manually, and you do not need to
            perform any further setup steps on the joining member.
     </p>
    </li>
    <li class="listitem">
     <p>
      For a replica in a source/replica MySQL replication
            topology, first clone the data from the donor MySQL server
            instance to the recipient manually. The donor must be a
            source or replica in the replication topology. For cloning
            instructions, see
      <a class="xref" href="clone-plugin-remote.html" title="7.6.7.3 Cloning Remote Data">
       Section 7.6.7.3, “Cloning Remote Data”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      After the cloning operation completes successfully, if you
            want to use the same replication channels on the recipient
            MySQL server instance that were present on the donor, verify
            which of them can resume replication automatically in the
            source/replica MySQL replication topology, and which need to
            be set up manually.
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         For GTID-based replication, if the recipient is
                configured with
         <a class="link" href="replication-options-gtids.html#sysvar_gtid_mode">
          <code class="literal">
           gtid_mode=ON
          </code>
         </a>
         and has
                cloned from a donor with
         <a class="link" href="replication-options-gtids.html#sysvar_gtid_mode">
          <code class="literal">
           gtid_mode=ON
          </code>
         </a>
         ,
         <code class="literal">
          ON_PERMISSIVE
         </code>
         , or
         <code class="literal">
          OFF_PERMISSIVE
         </code>
         , the
         <a class="link" href="replication-options-gtids.html#sysvar_gtid_executed">
          <code class="literal">
           gtid_executed
          </code>
         </a>
         GTID set
                from the donor is applied on the recipient. If the
                recipient is cloned from a replica already in the
                topology, replication channels on the recipient that use
                GTID auto-positioning can resume replication
                automatically after the cloning operation when the
                channel is started. You do not need to perform any
                manual setup if you just want to use these same
                channels.
        </p>
       </li>
       <li class="listitem">
        <p>
         For binary log file position based replication, the
                binary log position from the donor is applied on the
                recipient. Replication channels on the recipient that
                use binary log file position based replication
                automatically attempt to carry out the relay log
                recovery process, using the cloned relay log
                information, before restarting replication. For a
                single-threaded replica
                (
         <a class="link" href="replication-options-replica.html#sysvar_replica_parallel_workers">
          <code class="literal">
           replica_parallel_workers
          </code>
         </a>
         is set to 0), relay log recovery should succeed in the
                absence of any other issues, enabling the channel to
                resume replication with no further setup. For a
                multithreaded replica
                (
         <a class="link" href="replication-options-replica.html#sysvar_replica_parallel_workers">
          <code class="literal">
           replica_parallel_workers
          </code>
         </a>
         is greater than 0), relay log recovery is likely to fail
                because it cannot usually be completed automatically. In
                this case, an error message is issued, and you must set
                the channel up manually.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      If you need to set up cloned replication channels manually,
            or want to use different replication channels on the
            recipient, the following instructions provide a summary and
            abbreviated examples for adding a recipient MySQL server
            instance to a replication topology. Also refer to the
            detailed instructions that apply to your replication setup.
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: disc; ">
       <li class="listitem">
        <p>
         To add a recipient MySQL server instance to a MySQL
                replication topology that uses GTID-based transactions
                as the replication data source, configure the instance
                as required, following the instructions in
         <a class="xref" href="replication-gtids-howto.html" title="19.1.3.4 Setting Up Replication Using GTIDs">
          Section 19.1.3.4, “Setting Up Replication Using GTIDs”
         </a>
         . Add
                replication channels for the instance as shown in the
                following abbreviated example. The
         <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 must define the host address and
                port number of the source, and the
         <code class="literal">
          SOURCE_AUTO_POSITION
         </code>
         option should be
                enabled, as shown:
        </p>
        <div class="copytoclipboard-wrapper">
         <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59175142"><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">CHANGE</span> <span class="token keyword">SOURCE</span> <span class="token keyword">TO</span> <span class="token keyword">SOURCE_HOST</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">source_host_name</em>'</span><span class="token punctuation">,</span> <span class="token keyword">SOURCE_PORT</span> <span class="token operator">=</span> <em class="replaceable">source_port_num</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">SOURCE_AUTO_POSITION</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span>
       <span class="token keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">'<em class="replaceable">setup_channel</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">START</span> <span class="token keyword">REPLICA</span> <span class="token keyword">USER</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">user_name</em>'</span> <span class="token keyword">PASSWORD</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">password</em>'</span> <span class="token keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">'<em class="replaceable">setup_channel</em>'</span><span class="token punctuation">;</span></code></pre>
        </div>
       </li>
       <li class="listitem">
        <p>
         To add a recipient MySQL server instance to a MySQL
                replication topology that uses binary log file position
                based replication, configure the instance as required,
                following the instructions in
         <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>
         . Add replication
                channels for the instance as shown in the following
                abbreviated example, using the binary log position that
                was transferred to the recipient during the cloning
                operation:
        </p>
        <div class="copytoclipboard-wrapper">
         <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa3444900"><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">SELECT</span> BINLOG_FILE<span class="token punctuation">,</span> BINLOG_POSITION <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>clone_status<span class="token punctuation">;</span>
<span class="token keyword">CHANGE</span> <span class="token keyword">SOURCE</span> <span class="token keyword">TO</span> <span class="token keyword">SOURCE_HOST</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">source_host_name</em>'</span><span class="token punctuation">,</span> <span class="token keyword">SOURCE_PORT</span> <span class="token operator">=</span> <em class="replaceable">source_port_num</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">SOURCE_LOG_FILE</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">source_log_name</em>'</span><span class="token punctuation">,</span>
       <span class="token keyword">SOURCE_LOG_POS</span> <span class="token operator">=</span> <span class="token keyword"><em class="replaceable">source_log_pos</em></span><span class="token punctuation">,</span>
       <span class="token keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">'<em class="replaceable">setup_channel</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">START</span> <span class="token keyword">REPLICA</span> <span class="token keyword">USER</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">user_name</em>'</span> <span class="token keyword">PASSWORD</span> <span class="token operator">=</span> <span class="token string">'<em class="replaceable">password</em>'</span> <span class="token keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">'<em class="replaceable">setup_channel</em>'</span><span class="token punctuation">;</span></code></pre>
        </div>
       </li>
      </ul>
     </div>
    </li>
   </ol>
  </div>
 </div>
 <br/>
</div>
