<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="mysql-cluster-connection-strings">
      </a>
      25.4.3.3 NDB Cluster Connection Strings
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045120584736">
  </a>
  <a class="indexterm" name="idm46045120583248">
  </a>
  <p>
   With the exception of the NDB Cluster management server
        (
   <a class="link" href="mysql-cluster-programs-ndb-mgmd.html" title="25.5.4 ndb_mgmd — The NDB Cluster Management Server Daemon">
    <span class="command">
     <strong>
      ndb_mgmd
     </strong>
    </span>
   </a>
   ), each node that is part of an NDB
        Cluster requires a
   <span class="firstterm">
    connection
        string
   </span>
   that points to the management server's
        location. This connection string is used in establishing a
        connection to the management server as well as in performing
        other tasks depending on the node's role in the cluster. The
        syntax for a connection string is as follows:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa52757715"><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-simple"><span class="token punctuation">[</span>nodeid<span class="token operator">=</span><em class="replaceable">node_id</em><span class="token punctuation">,</span> <span class="token punctuation">]</span><em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">host<span class="token operator">-</span>definition</em><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 punctuation">]</span><span class="token punctuation">]</span>

<em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token operator">:</span>
    <em class="replaceable">host_name</em><span class="token punctuation">[</span><span class="token operator">:</span><em class="replaceable">port_number</em><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   <code class="literal">
    node_id
   </code>
   is an integer greater than or equal
        to 1 which identifies a node in
   <code class="filename">
    config.ini
   </code>
   .
   <em class="replaceable">
    <code>
     host_name
    </code>
   </em>
   is a string representing a
        valid Internet host name or IP address.
   <em class="replaceable">
    <code>
     port_number
    </code>
   </em>
   is an integer referring
        to a TCP/IP port number.
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa3965780"><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-simple">example 1 <span class="token punctuation">(</span>long<span class="token punctuation">)</span><span class="token operator">:</span>    "nodeid<span class="token operator">=</span>2<span class="token punctuation">,</span>myhost1<span class="token operator">:</span>1100<span class="token punctuation">,</span>myhost2<span class="token operator">:</span>1100<span class="token punctuation">,</span>198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>3<span class="token operator">:</span>1200"
example 2 <span class="token punctuation">(</span>short<span class="token punctuation">)</span><span class="token operator">:</span>   "myhost1"</code></pre>
  </div>
  <p>
   <code class="literal">
    localhost:1186
   </code>
   is used as the default
        connection string value if none is provided. If
   <em class="replaceable">
    <code>
     port_num
    </code>
   </em>
   is omitted from the
        connection string, the default port is 1186. This port should
        always be available on the network because it has been assigned
        by IANA for this purpose (see
   <a class="ulink" href="http://www.iana.org/assignments/port-numbers" target="_blank">
    http://www.iana.org/assignments/port-numbers
   </a>
   for
        details).
  </p>
  <p>
   By listing multiple host definitions, it is possible to
        designate several redundant management servers. An NDB Cluster
        data or API node attempts to contact successive management
        servers on each host in the order specified, until a successful
        connection has been established.
  </p>
  <p>
   It is also possible to specify in a connection string one or
        more bind addresses to be used by nodes having multiple network
        interfaces for connecting to management servers. A bind address
        consists of a hostname or network address and an optional port
        number. This enhanced syntax for connection strings is shown
        here:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa38299799"><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-simple"><span class="token punctuation">[</span>nodeid<span class="token operator">=</span><em class="replaceable">node_id</em><span class="token punctuation">,</span> <span class="token punctuation">]</span>
    <span class="token punctuation">[</span>bind<span class="token operator">-</span>address<span class="token operator">=</span><em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">,</span> <span class="token punctuation">]</span>
    <em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">[</span><span class="token punctuation">;</span> bind<span class="token operator">-</span>address<span class="token operator">=</span><em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">]</span>
    <em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token punctuation">[</span><span class="token punctuation">;</span> bind<span class="token operator">-</span>address<span class="token operator">=</span><em class="replaceable">host<span class="token operator">-</span>definition</em><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 punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">]</span>

<em class="replaceable">host<span class="token operator">-</span>definition</em><span class="token operator">:</span>
    <em class="replaceable">host_name</em><span class="token punctuation">[</span><span class="token operator">:</span><em class="replaceable">port_number</em><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   If a single bind address is used in the connection string
   <span class="emphasis">
    <em>
     prior
    </em>
   </span>
   to specifying any management hosts,
        then this address is used as the default for connecting to any
        of them (unless overridden for a given management server; see
        later in this section for an example). For example, the
        following connection string causes the node to use
   <code class="literal">
    198.51.100.242
   </code>
   regardless of the management
        server to which it connects:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa61625075"><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-simple">bind<span class="token operator">-</span>address<span class="token operator">=</span>198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>242<span class="token punctuation">,</span> poseidon<span class="token operator">:</span>1186<span class="token punctuation">,</span> perch<span class="token operator">:</span>1186</code></pre>
  </div>
  <p>
   If a bind address is specified
   <span class="emphasis">
    <em>
     following
    </em>
   </span>
   a
        management host definition, then it is used only for connecting
        to that management node. Consider the following connection
        string:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa42426391"><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-simple">poseidon<span class="token operator">:</span>1186<span class="token punctuation">;</span>bind<span class="token operator">-</span>address<span class="token operator">=</span>localhost<span class="token punctuation">,</span> perch<span class="token operator">:</span>1186<span class="token punctuation">;</span>bind<span class="token operator">-</span>address<span class="token operator">=</span>198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>242</code></pre>
  </div>
  <p>
   In this case, the node uses
   <code class="literal">
    localhost
   </code>
   to
        connect to the management server running on the host named
   <code class="literal">
    poseidon
   </code>
   and
   <code class="literal">
    198.51.100.242
   </code>
   to connect to the management
        server running on the host named
   <code class="literal">
    perch
   </code>
   .
  </p>
  <p>
   You can specify a default bind address and then override this
        default for one or more specific management hosts. In the
        following example,
   <code class="literal">
    localhost
   </code>
   is used for
        connecting to the management server running on host
   <code class="literal">
    poseidon
   </code>
   ; since
   <code class="literal">
    198.51.100.242
   </code>
   is specified first (before any
        management server definitions), it is the default bind address
        and so is used for connecting to the management servers on hosts
   <code class="literal">
    perch
   </code>
   and
   <code class="literal">
    orca
   </code>
   :
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa86273029"><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-simple">bind<span class="token operator">-</span>address<span class="token operator">=</span>198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>242<span class="token punctuation">,</span>poseidon<span class="token operator">:</span>1186<span class="token punctuation">;</span>bind<span class="token operator">-</span>address<span class="token operator">=</span>localhost<span class="token punctuation">,</span>perch<span class="token operator">:</span>1186<span class="token punctuation">,</span>orca<span class="token operator">:</span>2200</code></pre>
  </div>
  <p>
   There are a number of different ways to specify the connection
        string:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Each executable has its own command-line option which
            enables specifying the management server at startup. (See
            the documentation for the respective executable.)
     </p>
    </li>
    <li class="listitem">
     <p>
      It is also possible to set the connection string for all
            nodes in the cluster at once by placing it in a
      <code class="literal">
       [mysql_cluster]
      </code>
      section in the management
            server's
      <code class="filename">
       my.cnf
      </code>
      file.
     </p>
    </li>
    <li class="listitem">
     <p>
      For backward compatibility, two other options are available,
            using the same syntax:
     </p>
     <div class="orderedlist">
      <ol class="orderedlist" type="1">
       <li class="listitem">
        <p>
         Set the
         <code class="envar">
          NDB_CONNECTSTRING
         </code>
         environment
                variable to contain the connection string.
        </p>
        <p>
         This should be considered deprecated, and not used in
                new installations.
        </p>
       </li>
       <li class="listitem">
        <p>
         Write the connection string for each executable into a
                text file named
         <code class="filename">
          Ndb.cfg
         </code>
         and place
                this file in the executable's startup directory.
        </p>
        <p>
         Use of this file is deprecated in NDB 8.4.3; you should
                expect it to be removed in a future release of MySQL
                Cluster.
        </p>
       </li>
      </ol>
     </div>
    </li>
   </ul>
  </div>
  <p>
   The recommended method for specifying the connection string is
        to set it on the command line or in the
   <code class="filename">
    my.cnf
   </code>
   file for each executable.
  </p>
 </div>
 <br/>
</div>
