<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="replication-multi-source-adding-gtid-master">
      </a>
      19.1.5.3 Adding GTID-Based Sources to a Multi-Source Replica
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045145226416">
  </a>
  <p>
   These steps assume you have enabled GTIDs for transactions on the
      sources using
   <a class="link" href="replication-options-gtids.html#sysvar_gtid_mode">
    <code class="literal">
     gtid_mode=ON
    </code>
   </a>
   ,
      created a replication user, ensured that the replica is using
   <code class="literal">
    TABLE
   </code>
   based replication applier metadata
      repositories, and provisioned the replica with data from the
      sources if appropriate.
  </p>
  <p>
   Use
   <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>
   to
      configure a replication channel for each source on the replica
      (see
   <a class="xref" href="replication-channels.html" title="19.2.2 Replication Channels">
    Section 19.2.2, “Replication Channels”
   </a>
   ). The
   <code class="literal">
    FOR
      CHANNEL
   </code>
   clause is used to specify the channel. For
      GTID-based replication, GTID auto-positioning is used to
      synchronize with the source (see
   <a class="xref" href="replication-gtids-auto-positioning.html" title="19.1.3.3 GTID Auto-Positioning">
    Section 19.1.3.3, “GTID Auto-Positioning”
   </a>
   ). The
   <code class="literal">
    SOURCE_AUTO_POSITION
   </code>
   option is set to specify
      the use of auto-positioning.
  </p>
  <p>
   For example, to add
   <code class="literal">
    source1
   </code>
   and
   <code class="literal">
    source2
   </code>
   as sources to the replica, use 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 to issue the statement twice on
      the replica, like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa57249422"><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">CHANGE</span> <span class="token keyword">REPLICATION</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">"source1"</span><span class="token punctuation">,</span> <span class="token keyword">SOURCE_USER</span><span class="token operator">=</span><span class="token string">"ted"</span><span class="token punctuation">,</span> \
<span class="token keyword">SOURCE_PASSWORD</span><span class="token operator">=</span><span class="token string">"<em class="replaceable">password</em>"</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 keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">"source_1"</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&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 keyword">SOURCE_HOST</span><span class="token operator">=</span><span class="token string">"source2"</span><span class="token punctuation">,</span> <span class="token keyword">SOURCE_USER</span><span class="token operator">=</span><span class="token string">"ted"</span><span class="token punctuation">,</span> \
<span class="token keyword">SOURCE_PASSWORD</span><span class="token operator">=</span><span class="token string">"<em class="replaceable">password</em>"</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 keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">"source_2"</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   To make the replica replicate only database
   <code class="literal">
    db1
   </code>
   from
   <code class="literal">
    source1
   </code>
   , and only database
   <code class="literal">
    db2
   </code>
   from
   <code class="literal">
    source2
   </code>
   , use 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 to issue the
   <a class="link" href="change-replication-filter.html" title="15.4.2.1 CHANGE REPLICATION FILTER Statement">
    <code class="literal">
     CHANGE REPLICATION FILTER
    </code>
   </a>
   statement
      for each channel, like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa5565345"><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">CHANGE</span> <span class="token keyword">REPLICATION</span> <span class="token keyword">FILTER</span> <span class="token keyword">REPLICATE_WILD_DO_TABLE</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token string">'db1.%'</span><span class="token punctuation">)</span> <span class="token keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">"source_1"</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">CHANGE</span> <span class="token keyword">REPLICATION</span> <span class="token keyword">FILTER</span> <span class="token keyword">REPLICATE_WILD_DO_TABLE</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token string">'db2.%'</span><span class="token punctuation">)</span> <span class="token keyword">FOR</span> <span class="token keyword">CHANNEL</span> <span class="token string">"source_2"</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   For the full syntax of the
   <a class="link" href="change-replication-filter.html" title="15.4.2.1 CHANGE REPLICATION FILTER Statement">
    <code class="literal">
     CHANGE REPLICATION
      FILTER
    </code>
   </a>
   statement and other available options, see
   <a class="xref" href="change-replication-filter.html" title="15.4.2.1 CHANGE REPLICATION FILTER Statement">
    Section 15.4.2.1, “CHANGE REPLICATION FILTER Statement”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
