<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="federated-create-connection">
      </a>
      18.8.2.1 Creating a FEDERATED Table Using CONNECTION
     </h4>
    </div>
   </div>
  </div>
  <p>
   To use the first method, you must specify the
   <code class="literal">
    CONNECTION
   </code>
   string after the engine type in a
   <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
    <code class="literal">
     CREATE TABLE
    </code>
   </a>
   statement. For
        example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa81982638"><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">CREATE</span> <span class="token keyword">TABLE</span> federated_table <span class="token punctuation">(</span>
    id     <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
    <span class="token keyword">name</span>   <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">''</span><span class="token punctuation">,</span>
    other  <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">DEFAULT</span> <span class="token string">'0'</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span>  <span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">INDEX</span> <span class="token keyword">name</span> <span class="token punctuation">(</span><span class="token keyword">name</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">INDEX</span> other_key <span class="token punctuation">(</span>other<span class="token punctuation">)</span>
<span class="token punctuation">)</span>
<span class="token keyword">ENGINE</span><span class="token operator">=</span>FEDERATED
<span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4
<span class="token keyword">CONNECTION</span><span class="token operator">=</span><span class="token string">'mysql://fed_user@remote_host:9306/federated/test_table'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    <code class="literal">
     CONNECTION
    </code>
    replaces the
    <code class="literal">
     COMMENT
    </code>
    used in some previous versions of
          MySQL.
   </p>
  </div>
  <p>
   The
   <code class="literal">
    CONNECTION
   </code>
   string contains the
        information required to connect to the remote server containing
        the table in which the data physically resides. The connection
        string specifies the server name, login credentials, port number
        and database/table information. In the example, the remote table
        is on the server
   <code class="literal">
    remote_host
   </code>
   , using port
        9306. The name and port number should match the host name (or IP
        address) and port number of the remote MySQL server instance you
        want to use as your remote table.
  </p>
  <p>
   The format of the connection string is as follows:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa31285325"><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-none"><em class="replaceable">scheme</em>://<em class="replaceable">user_name</em>[:<em class="replaceable">password</em>]@<em class="replaceable">host_name</em>[:<em class="replaceable">port_num</em>]/<em class="replaceable">db_name</em>/<em class="replaceable">tbl_name</em></code></pre>
  </div>
  <p>
   Where:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        scheme
       </code>
      </em>
      : A recognized connection
            protocol. Only
      <code class="literal">
       mysql
      </code>
      is supported as the
      <em class="replaceable">
       <code>
        scheme
       </code>
      </em>
      value at this point.
     </p>
    </li>
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        user_name
       </code>
      </em>
      : The user name for the
            connection. This user must have been created on the remote
            server, and must have suitable privileges to perform the
            required actions (
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      ,
      <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
       <code class="literal">
        INSERT
       </code>
      </a>
      ,
      <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
       <code class="literal">
        UPDATE
       </code>
      </a>
      , and so forth) on the
            remote table.
     </p>
    </li>
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        password
       </code>
      </em>
      : (Optional) The
            corresponding password for
      <em class="replaceable">
       <code>
        user_name
       </code>
      </em>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        host_name
       </code>
      </em>
      : The host name or IP
            address of the remote server.
     </p>
    </li>
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        port_num
       </code>
      </em>
      : (Optional) The port
            number for the remote server. The default is 3306.
     </p>
    </li>
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        db_name
       </code>
      </em>
      : The name of the database
            holding the remote table.
     </p>
    </li>
    <li class="listitem">
     <p>
      <em class="replaceable">
       <code>
        tbl_name
       </code>
      </em>
      : The name of the remote
            table. The name of the local and the remote table do not
            have to match.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Sample connection strings:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa33244394"><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">CONNECTION</span><span class="token operator">=</span><span class="token string">'mysql://username:password@hostname:port/database/tablename'</span>
<span class="token keyword">CONNECTION</span><span class="token operator">=</span><span class="token string">'mysql://username@hostname/database/tablename'</span>
<span class="token keyword">CONNECTION</span><span class="token operator">=</span><span class="token string">'mysql://username:password@hostname/database/tablename'</span></code></pre>
  </div>
 </div>
 <br/>
</div>
