<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="mysql-cluster-replication-starting">
      </a>
      25.7.6 Starting NDB Cluster Replication (Single Replication Channel)
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045086100992">
  </a>
  <p>
   This section outlines the procedure for starting NDB Cluster
      replication using a single replication channel.
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Start the MySQL replication source server by issuing this
          command, where
      <em class="replaceable">
       <code>
        id
       </code>
      </em>
      is this
          server's unique ID (see
      <a class="xref" href="mysql-cluster-replication-general.html" title="25.7.2 General Requirements for NDB Cluster Replication">
       Section 25.7.2, “General Requirements for NDB Cluster Replication”
      </a>
      ):
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa33674089"><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-terminal"><span class="token prompt">shell<em class="replaceable">S</em>&gt;</span><span class="token command"> mysqld</span> <span class="token property">--ndbcluster</span> <span class="token constant">--server-id</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">id</em></span> \
        <span class="token property">--log-bin</span> <span class="token property">--ndb-log-bin</span> &amp;</code></pre>
     </div>
     <p>
      This starts the server's
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      process with binary logging enabled using the proper logging
          format. It is also necessary to enable logging of updates to
      <code class="literal">
       NDB
      </code>
      tables explicitly, using the
      <a class="link" href="mysql-cluster-options-variables.html#sysvar_ndb_log_bin">
       <code class="option">
        --ndb-log-bin
       </code>
      </a>
      option.
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       You can also start the source with
       <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format">
        <code class="option">
         --binlog-format=MIXED
        </code>
       </a>
       , in
            which case row-based replication is used automatically when
            replicating between clusters. Statement-based binary logging
            is not supported for NDB Cluster Replication (see
       <a class="xref" href="mysql-cluster-replication-general.html" title="25.7.2 General Requirements for NDB Cluster Replication">
        Section 25.7.2, “General Requirements for NDB Cluster Replication”
       </a>
       ).
      </p>
     </div>
    </li>
    <li class="listitem">
     <p>
      Start the MySQL replica server as shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa81595080"><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-terminal">shell<em class="replaceable">R</em>&gt; mysqld <span class="token property">--ndbcluster</span> <span class="token constant">--server-id</span><span class="token attr-value"><span class="token punctuation">=</span><em class="replaceable">id</em></span> &amp;</code></pre>
     </div>
     <p>
      In the command just shown,
      <em class="replaceable">
       <code>
        id
       </code>
      </em>
      is
          the replica server's unique ID. It is not necessary to
          enable logging on the replica.
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       Unless you want replication to begin immediately, delay the
            start of the replication threads until the appropriate
       <a class="link" href="start-replica.html" title="15.4.2.4 START REPLICA Statement">
        <code class="literal">
         START REPLICA
        </code>
       </a>
       statement has
            been issued, as explained in Step 4 below. You can do this
            by starting the replica with
       <a class="link" href="replication-options-replica.html#option_mysqld_skip-replica-start">
        <code class="option">
         --skip-replica-start
        </code>
       </a>
       .
      </p>
     </div>
    </li>
    <li class="listitem">
     <p>
      It is necessary to synchronize the replica server with the
          source server's replication binary log. If binary logging
          has not previously been running on the source, run the
          following statement on the replica:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34464179"><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">mysql<em class="replaceable">R</em><span class="token operator">&gt;</span> <span class="token keyword">CHANGE</span> <span class="token keyword">REPLICATION</span> <span class="token keyword">SOURCE</span> <span class="token keyword">TO</span>
<span class="token prompt">     -&gt;</span> <span class="token keyword">SOURCE_LOG_FILE</span><span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span>
<span class="token prompt">     -&gt;</span> <span class="token keyword">SOURCE_LOG_POS</span><span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">;</span></code></pre>
     </div>
     <p>
      This instructs the replica to begin reading the source
          server's binary log from the log's starting point.
          Otherwise—that is, if you are loading data from the
          source using a backup—see
      <a class="xref" href="mysql-cluster-replication-failover.html" title="25.7.8 Implementing Failover with NDB Cluster Replication">
       Section 25.7.8, “Implementing Failover with NDB Cluster Replication”
      </a>
      , for
          information on how to obtain the correct values to use for
      <code class="literal">
       SOURCE_LOG_FILE
      </code>
      and
      <code class="literal">
       SOURCE_LOG_POS
      </code>
      in such cases.
     </p>
    </li>
    <li class="listitem">
     <p>
      Finally, instruct the replica to begin applying replication by
          issuing this command from the
      <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
       <span class="command">
        <strong>
         mysql
        </strong>
       </span>
      </a>
      client
          on the replica:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa39502227"><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">mysql<em class="replaceable">R</em><span class="token operator">&gt;</span> <span class="token keyword">START</span> <span class="token keyword">REPLICA</span><span class="token punctuation">;</span></code></pre>
     </div>
     <p>
      This also initiates the transmission of data and changes from
          the source to the replica.
     </p>
    </li>
   </ol>
  </div>
  <p>
   It is also possible to use two replication channels, in a manner
      similar to the procedure described in the next section; the
      differences between this and using a single replication channel
      are covered in
   <a class="xref" href="mysql-cluster-replication-two-channels.html" title="25.7.7 Using Two Replication Channels for NDB Cluster Replication">
    Section 25.7.7, “Using Two Replication Channels for NDB Cluster Replication”
   </a>
   .
  </p>
  <a class="indexterm" name="idm46045086065488">
  </a>
  <p>
   It is also possible to improve cluster replication performance by
      enabling
   <span class="firstterm">
    batched updates
   </span>
   .
      This can be accomplished by setting the system variable
   <a class="link" href="mysql-cluster-options-variables.html#sysvar_replica_allow_batching">
    <code class="literal">
     replica_allow_batching
    </code>
   </a>
   on the
      replicas'
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   processes. Normally,
      updates are applied as soon as they are received. However, the use
      of batching causes updates to be applied in batches of 32 KB each;
      this can result in higher throughput and less CPU usage,
      particularly where individual updates are relatively small.
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    Batching works on a per-epoch basis; updates belonging to more
        than one transaction can be sent as part of the same batch.
   </p>
   <p>
    All outstanding updates are applied when the end of an epoch is
        reached, even if the updates total less than 32 KB.
   </p>
  </div>
  <a class="indexterm" name="idm46045086058896">
  </a>
  <a class="indexterm" name="idm46045086057824">
  </a>
  <p>
   Batching can be turned on and off at runtime. To activate it at
      runtime, you can use either of these two statements:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99975536"><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> <span class="token keyword">GLOBAL</span> replica_allow_batching <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> <span class="token keyword">GLOBAL</span> replica_allow_batching <span class="token operator">=</span> <span class="token keyword">ON</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   If a particular batch causes problems (such as a statement whose
      effects do not appear to be replicated correctly), batching can be
      deactivated using either of the following statements:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa30714248"><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> <span class="token keyword">GLOBAL</span> replica_allow_batching <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> <span class="token keyword">GLOBAL</span> replica_allow_batching <span class="token operator">=</span> <span class="token keyword">OFF</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   You can check whether batching is currently being used by means of
      an appropriate
   <a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement">
    <code class="literal">
     SHOW VARIABLES
    </code>
   </a>
   statement, like this one:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa4905650"><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">SHOW</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'replica%'</span><span class="token punctuation">;</span></code></pre>
  </div>
 </div>
 <br/>
</div>
