<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="create-server">
      </a>
      15.1.18 CREATE SERVER Statement
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045187044400">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa7591098"><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">SERVER</span> <em class="replaceable">server_name</em>
    <span class="token keyword">FOREIGN</span> <span class="token keyword">DATA</span> <span class="token keyword">WRAPPER</span> <em class="replaceable">wrapper_name</em>
    <span class="token keyword">OPTIONS</span> <span class="token punctuation">(</span><span class="token keyword"><em class="replaceable">option</em></span> <span class="token punctuation">[</span><span class="token punctuation">,</span> <span class="token keyword"><em class="replaceable">option</em></span><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>

<span class="token keyword"><em class="replaceable">option</em></span>: {
    <span class="token keyword">HOST</span> <span class="token keyword"></span><em class="replaceable"><span class="token keyword">character</span><span class="token operator">-</span>literal</em>
  <span class="token operator">|</span> <span class="token keyword">DATABASE</span> <span class="token keyword"></span><em class="replaceable"><span class="token keyword">character</span><span class="token operator">-</span>literal</em>
  <span class="token operator">|</span> <span class="token keyword">USER</span> <span class="token keyword"></span><em class="replaceable"><span class="token keyword">character</span><span class="token operator">-</span>literal</em>
  <span class="token operator">|</span> <span class="token keyword">PASSWORD</span> <span class="token keyword"></span><em class="replaceable"><span class="token keyword">character</span><span class="token operator">-</span>literal</em>
  <span class="token operator">|</span> <span class="token keyword">SOCKET</span> <span class="token keyword"></span><em class="replaceable"><span class="token keyword">character</span><span class="token operator">-</span>literal</em>
  <span class="token operator">|</span> <span class="token keyword">OWNER</span> <span class="token keyword"></span><em class="replaceable"><span class="token keyword">character</span><span class="token operator">-</span>literal</em>
  <span class="token operator">|</span> <span class="token keyword">PORT</span> <span class="token datatype"></span><em class="replaceable"><span class="token datatype">numeric</span><span class="token operator">-</span>literal</em>
}</code></pre>
  </div>
  <p>
   This statement creates the definition of a server for use with the
   <code class="literal">
    FEDERATED
   </code>
   storage engine. The
   <code class="literal">
    CREATE
      SERVER
   </code>
   statement creates a new row in the
   <code class="literal">
    servers
   </code>
   table in the
   <code class="literal">
    mysql
   </code>
   database. This statement requires the
   <a class="link" href="privileges-provided.html#priv_super">
    <code class="literal">
     SUPER
    </code>
   </a>
   privilege.
  </p>
  <p>
   The
   <code class="literal">
    <em class="replaceable">
     <code>
      server_name
     </code>
    </em>
   </code>
   should be a unique reference to the server. Server definitions are
      global within the scope of the server, it is not possible to
      qualify the server definition to a specific database.
   <code class="literal">
    <em class="replaceable">
     <code>
      server_name
     </code>
    </em>
   </code>
   has a
      maximum length of 64 characters (names longer than 64 characters
      are silently truncated), and is case-insensitive. You may specify
      the name as a quoted string.
  </p>
  <p>
   The
   <code class="literal">
    <em class="replaceable">
     <code>
      wrapper_name
     </code>
    </em>
   </code>
   is
      an identifier and may be quoted with single quotation marks.
  </p>
  <p>
   For each
   <code class="literal">
    <em class="replaceable">
     <code>
      option
     </code>
    </em>
   </code>
   you
      must specify either a character literal or numeric literal.
      Character literals are UTF-8, support a maximum length of 64
      characters and default to a blank (empty) string. String literals
      are silently truncated to 64 characters. Numeric literals must be
      a number between 0 and 9999, default value is 0.
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    The
    <code class="literal">
     OWNER
    </code>
    option is currently not applied,
        and has no effect on the ownership or operation of the server
        connection that is created.
   </p>
  </div>
  <p>
   The
   <code class="literal">
    CREATE SERVER
   </code>
   statement creates an entry in
      the
   <code class="literal">
    mysql.servers
   </code>
   table that can later be used
      with the
   <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
    <code class="literal">
     CREATE TABLE
    </code>
   </a>
   statement
      when creating a
   <code class="literal">
    FEDERATED
   </code>
   table. The options
      that you specify are used to populate the columns in the
   <code class="literal">
    mysql.servers
   </code>
   table. The table columns are
   <code class="literal">
    Server_name
   </code>
   ,
   <code class="literal">
    Host
   </code>
   ,
   <code class="literal">
    Db
   </code>
   ,
   <code class="literal">
    Username
   </code>
   ,
   <code class="literal">
    Password
   </code>
   ,
   <code class="literal">
    Port
   </code>
   and
   <code class="literal">
    Socket
   </code>
   .
  </p>
  <p>
   For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa96792536"><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">SERVER</span> s
<span class="token keyword">FOREIGN</span> <span class="token keyword">DATA</span> <span class="token keyword">WRAPPER</span> mysql
<span class="token keyword">OPTIONS</span> <span class="token punctuation">(</span><span class="token keyword">USER</span> <span class="token string">'Remote'</span><span class="token punctuation">,</span> <span class="token keyword">HOST</span> <span class="token string">'198.51.100.106'</span><span class="token punctuation">,</span> <span class="token keyword">DATABASE</span> <span class="token string">'test'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   Be sure to specify all options necessary to establish a connection
      to the server. The user name, host name, and database name are
      mandatory. Other options might be required as well, such as
      password.
  </p>
  <p>
   The data stored in the table can be used when creating a
      connection to a
   <code class="literal">
    FEDERATED
   </code>
   table:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa74755280"><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> t <span class="token punctuation">(</span>s1 <span class="token datatype">INT</span><span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span>FEDERATED <span class="token keyword">CONNECTION</span><span class="token operator">=</span><span class="token string">'s'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   For more information, see
   <a class="xref" href="federated-storage-engine.html" title="18.8 The FEDERATED Storage Engine">
    Section 18.8, “The FEDERATED Storage Engine”
   </a>
   .
  </p>
  <p>
   <code class="literal">
    CREATE SERVER
   </code>
   causes an implicit commit. 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>
   <code class="literal">
    CREATE SERVER
   </code>
   is not written to the binary log,
      regardless of the logging format that is in use.
  </p>
 </div>
 <br/>
</div>
