<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="network-namespace-support">
      </a>
      7.1.14 Network Namespace Support
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045260630096">
  </a>
  <a class="indexterm" name="idm46045260629024">
  </a>
  <p>
   A network namespace is a logical copy of the network stack from
      the host system. Network namespaces are useful for setting up
      containers or virtual environments. Each namespace has its own IP
      addresses, network interfaces, routing tables, and so forth. The
      default or global namespace is the one in which the host system
      physical interfaces exist.
  </p>
  <p>
   Namespace-specific address spaces can lead to problems when MySQL
      connections cross namespaces. For example, the network address
      space for a MySQL instance running in a container or virtual
      network may differ from the address space of the host machine.
      This can produce phenomena such as a client connection from an
      address in one namespace appearing to the MySQL server to be
      coming from a different address, even for client and server
      running on the same machine. Suppose that both processes run on a
      host with IP address
   <code class="literal">
    203.0.113.10
   </code>
   but use
      different namespaces. A connection may produce a result like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa99221306"><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 operator">&gt;</span> mysql <span class="token operator">--</span>user<span class="token operator">=</span>admin <span class="token operator">--</span>host<span class="token operator">=</span>203<span class="token punctuation">.</span>0<span class="token punctuation">.</span>113<span class="token punctuation">.</span>10 <span class="token operator">--</span>protocol<span class="token operator">=</span>tcp

mysql<span class="token operator">&gt;</span> SELECT USER<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span>
<span class="token operator">|</span> USER<span class="token punctuation">(</span><span class="token punctuation">)</span>             <span class="token operator">|</span>
<span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span>
<span class="token operator">|</span> admin@198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>2 <span class="token operator">|</span>
<span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span></code></pre>
  </div>
  <p>
   In this case, the expected
   <a class="link" href="information-functions.html#function_user">
    <code class="literal">
     USER()
    </code>
   </a>
   value is
   <code class="literal">
    admin@203.0.113.10
   </code>
   . Such behavior can
      make it difficult to assign account permissions properly if the
      address from which an connection originates is not what it
      appears.
  </p>
  <p>
   To address this issue, MySQL enables specifying the network
      namespace to use for TCP/IP connections, so that both endpoints of
      connections use an agreed-upon common address space.
  </p>
  <p>
   MySQL supports network namespaces on platforms that implement
      them. Support within MySQL applies to:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The MySQL server,
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      X Plugin.
     </p>
    </li>
    <li class="listitem">
     <p>
      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 and the
      <span class="command">
       <strong>
        mysqlxtest
       </strong>
      </span>
      test suite client. (Other
          clients are not supported. They must be invoked from within
          the network namespace of the server to which they are to
          connect.)
     </p>
    </li>
    <li class="listitem">
     <p>
      Regular replication.
     </p>
    </li>
    <li class="listitem">
     <p>
      Group Replication, only when using the MySQL communication
          stack to establish group communication connections.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The following sections describe how to use network namespaces in
      MySQL:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="network-namespace-support.html#network-namespaces-host-prerequisites" title="Host System Prerequisites">
       Host System Prerequisites
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="network-namespace-support.html#network-namespaces-mysql-configuration" title="MySQL Configuration">
       MySQL Configuration
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="network-namespace-support.html#network-namespaces-monitoring" title="Network Namespace Monitoring">
       Network Namespace Monitoring
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="network-namespaces-host-prerequisites">
       </a>
       Host System Prerequisites
      </h4>
     </div>
    </div>
   </div>
   <p>
    Prior to using network namespace support in MySQL, these host
        system prerequisites must be satisfied:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       The host operating system must support network namespaces.
            (For example, Linux.)
      </p>
     </li>
     <li class="listitem">
      <p>
       Any network namespace to be used by MySQL must first be
            created on the host system.
      </p>
     </li>
     <li class="listitem">
      <p>
       Host name resolution must be configured by the system
            administrator to support network namespaces.
      </p>
      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
       <div class="admon-title">
        Note
       </div>
       <p>
        A known limitation is that, within MySQL, host name
              resolution does not work for names specified in network
              namespace-specific host files. For example, if the address
              for a host name in the
        <code class="literal">
         red
        </code>
        namespace is
              specified in the
        <code class="filename">
         /etc/netns/red/hosts
        </code>
        file, binding to the name fails on both the server and
              client sides. The workaround is to use the IP address
              rather than the host name.
       </p>
      </div>
     </li>
     <li class="listitem">
      <p>
       The system administrator must enable the
       <code class="literal">
        CAP_SYS_ADMIN
       </code>
       operating system privilege
            for the MySQL binaries that support network namespaces
            (
       <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
        <span class="command">
         <strong>
          mysqld
         </strong>
        </span>
       </a>
       ,
       <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
        <span class="command">
         <strong>
          mysql
         </strong>
        </span>
       </a>
       ,
       <span class="command">
        <strong>
         mysqlxtest
        </strong>
       </span>
       ).
      </p>
      <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
       <div class="admon-title">
        Important
       </div>
       <p>
        Enabling
        <code class="literal">
         CAP_SYS_ADMIN
        </code>
        is a security
              sensitive operation because it enables a process to
              perform other privileged actions in addition to setting
              namespaces. For a description of its effects, see
        <a class="ulink" href="https://man7.org/linux/man-pages/man7/capabilities.7.html" target="_blank">
         https://man7.org/linux/man-pages/man7/capabilities.7.html
        </a>
        .
       </p>
       <p>
        Because
        <code class="literal">
         CAP_SYS_ADMIN
        </code>
        must be enabled
              explicitly by the system administrator, MySQL binaries by
              default do not have network namespace support enabled. The
              system administrator should evaluate the security
              implications of running MySQL processes with
        <code class="literal">
         CAP_SYS_ADMIN
        </code>
        before enabling it.
       </p>
      </div>
     </li>
    </ul>
   </div>
   <p>
    The instructions in the following example set up network
        namespaces named
    <code class="literal">
     red
    </code>
    and
    <code class="literal">
     blue
    </code>
    . The names you choose may differ, as may
        the network addresses and interfaces on your host system.
   </p>
   <p>
    Invoke the commands shown here either as the
    <code class="literal">
     root
    </code>
    operating system user or by prefixing
        each command with
    <span class="command">
     <strong>
      sudo
     </strong>
    </span>
    . For example, to
        invoke the
    <span class="command">
     <strong>
      ip
     </strong>
    </span>
    or
    <span class="command">
     <strong>
      setcap
     </strong>
    </span>
    command if you are not
    <code class="literal">
     root
    </code>
    , use
    <span class="command">
     <strong>
      sudo ip
     </strong>
    </span>
    or
    <span class="command">
     <strong>
      sudo setcap
     </strong>
    </span>
    .
   </p>
   <p>
    To configure network namespaces, use the
    <span class="command">
     <strong>
      ip
     </strong>
    </span>
    command. For some operations, the
    <span class="command">
     <strong>
      ip
     </strong>
    </span>
    command
        must execute within a particular namespace (which must already
        exist). In such cases, begin the command like this:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa69926930"><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">ip netns exec <em class="replaceable">namespace_name</em></code></pre>
   </div>
   <p>
    For example, this command executes within the
    <code class="literal">
     red
    </code>
    namespace to bring up the loopback
        interface:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa92041966"><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">ip netns exec red ip link set lo up</code></pre>
   </div>
   <p>
    To add namespaces named
    <code class="literal">
     red
    </code>
    and
    <code class="literal">
     blue
    </code>
    , each with its own virtual Ethernet
        device used as a link between namespaces and its own loopback
        interface:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa75626178"><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">ip netns add red
ip link add veth-red type veth peer name vpeer-red
ip link set vpeer-red netns red
ip addr add 192<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">.</span>1/24 dev veth-red
ip link set veth-red up
ip netns exec red ip addr add 192<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">.</span>2/24 dev vpeer-red
ip netns exec red ip link set vpeer-red up
ip netns exec red ip link set lo up

ip netns add blue
ip link add veth-blue type veth peer name vpeer-blue
ip link set vpeer-blue netns blue
ip addr add 198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>1/24 dev veth-blue
ip link set veth-blue up
ip netns exec blue ip addr add 198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>2/24 dev vpeer-blue
ip netns exec blue ip link set vpeer-blue up
ip netns exec blue ip link set lo up

<span class="token comment" spellcheck="true"># if you want to enable inter-subnet routing...</span>
sysctl net<span class="token punctuation">.</span>ipv4<span class="token punctuation">.</span>ip_forward<span class="token attr-value"><span class="token punctuation">=</span>1</span>
ip netns exec red ip route add default via 192<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">.</span>1
ip netns exec blue ip route add default via 198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>1</code></pre>
   </div>
   <p>
    A diagram of the links between namespaces looks like this:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-none"><div class="docs-select-all right" id="sa67975921"><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">red              global           blue

192.0.2.2   &lt;=&gt;  192.0.2.1
(vpeer-red)      (veth-red)

                 198.51.100.1 &lt;=&gt; 198.51.100.2
                 (veth-blue)      (vpeer-blue)</code></pre>
   </div>
   <p>
    To check which namespaces and links exist:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa29643824"><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">ip netns list
ip link list</code></pre>
   </div>
   <p>
    To see the routing tables for the global and named namespaces:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa88437224"><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">ip route show
ip netns exec red ip route show
ip netns exec blue ip route show</code></pre>
   </div>
   <p>
    To remove the
    <code class="literal">
     red
    </code>
    and
    <code class="literal">
     blue
    </code>
    links and namespaces:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa84054608"><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">ip link del veth-red
ip link del veth-blue

ip netns del red
ip netns del blue

sysctl net<span class="token punctuation">.</span>ipv4<span class="token punctuation">.</span>ip_forward<span class="token attr-value"><span class="token punctuation">=</span>0</span></code></pre>
   </div>
   <p>
    So that the MySQL binaries that include network namespace
        support can actually use namespaces, you must grant them the
    <code class="literal">
     CAP_SYS_ADMIN
    </code>
    capability. The following
    <span class="command">
     <strong>
      setcap
     </strong>
    </span>
    commands assume that you have changed
        location to the directory containing your MySQL binaries (adjust
        the pathname for your system as necessary):
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa92882441"><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">cd /usr/local/mysql/bin</code></pre>
   </div>
   <p>
    To grant
    <code class="literal">
     CAP_SYS_ADMIN
    </code>
    capability to the
        appropriate binaries:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa47369150"><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">setcap cap_sys_admin+ep <span class="token punctuation">.</span>/mysqld
setcap cap_sys_admin+ep <span class="token punctuation">.</span>/mysql
setcap cap_sys_admin+ep <span class="token punctuation">.</span>/mysqlxtest</code></pre>
   </div>
   <p>
    To check
    <code class="literal">
     CAP_SYS_ADMIN
    </code>
    capability:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa30592321"><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">$&gt; </span><span class="token command">getcap</span> <span class="token punctuation">.</span>/mysqld <span class="token punctuation">.</span>/mysql <span class="token punctuation">.</span>/mysqlxtest
<span class="token punctuation">.</span>/mysqld = cap_sys_admin+ep
<span class="token punctuation">.</span>/mysql = cap_sys_admin+ep
<span class="token punctuation">.</span>/mysqlxtest = cap_sys_admin+ep</code></pre>
   </div>
   <p>
    To remove
    <code class="literal">
     CAP_SYS_ADMIN
    </code>
    capability:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa91835259"><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">setcap <span class="token property">-r</span> <span class="token punctuation">.</span>/mysqld
setcap <span class="token property">-r</span> <span class="token punctuation">.</span>/mysql
setcap <span class="token property">-r</span> <span class="token punctuation">.</span>/mysqlxtest</code></pre>
   </div>
   <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Important
    </div>
    <p>
     If you reinstall binaries to which you have previously applied
     <span class="command">
      <strong>
       setcap
      </strong>
     </span>
     , you must use
     <span class="command">
      <strong>
       setcap
      </strong>
     </span>
     again. For example, if you perform
          an in-place MySQL upgrade, failure to grant the
     <code class="literal">
      CAP_SYS_ADMIN
     </code>
     capability again results in
          namespace-related failures. The server fails with this error
          for attempts to bind to an address with a named namespace:
    </p>
    <div class="copytoclipboard-wrapper">
     <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa2792879"><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">[ERROR] [MY-013408] [Server] setns() failed with error 'Operation not permitted'</code></pre>
    </div>
    <p>
     A client invoked with the
     <a class="link" href="mysql-command-options.html#option_mysql_network-namespace">
      <code class="option">
       --network-namespace
      </code>
     </a>
     option fails
          like this:
    </p>
    <div class="copytoclipboard-wrapper">
     <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa85496059"><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">ERROR: Network namespace error: Operation not permitted</code></pre>
    </div>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="network-namespaces-mysql-configuration">
       </a>
       MySQL Configuration
      </h4>
     </div>
    </div>
   </div>
   <p>
    Assuming that the preceding host system prerequisites have been
        satisfied, MySQL enables configuring the server-side namespace
        for the listening (inbound) side of connections and the
        client-side namespace for the outbound side of connections.
   </p>
   <p>
    On the server side, the
    <a class="link" href="server-system-variables.html#sysvar_bind_address">
     <code class="literal">
      bind_address
     </code>
    </a>
    ,
    <a class="link" href="server-system-variables.html#sysvar_admin_address">
     <code class="literal">
      admin_address
     </code>
    </a>
    , and
    <a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_bind_address">
     <code class="literal">
      mysqlx_bind_address
     </code>
    </a>
    system
        variables have extended syntax for specifying the network
        namespace to use for a given IP address or host name on which to
        listen for incoming connections. To specify a namespace for an
        address, add a slash and the namespace name. For example, a
        server
    <code class="filename">
     my.cnf
    </code>
    file might contain these
        lines:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa85576297"><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-ini"><span class="token selector">[mysqld]</span>
<span class="token constant">bind_address</span> <span class="token attr-value"><span class="token punctuation">=</span> 127.0.1.1,192.0.2.2/red,198.51.100.2/blue</span>
<span class="token constant">admin_address</span> <span class="token attr-value"><span class="token punctuation">=</span> 102.0.2.2/red</span>
<span class="token constant">mysqlx_bind_address</span> <span class="token attr-value"><span class="token punctuation">=</span> 102.0.2.2/red</span></code></pre>
   </div>
   <p>
    These rules apply:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       A network namespace can be specified for an IP address or a
            host name.
      </p>
     </li>
     <li class="listitem">
      <p>
       A network namespace cannot be specified for a wildcard IP
            address.
      </p>
     </li>
     <li class="listitem">
      <p>
       For a given address, the network namespace is optional. If
            given, it must be specified as a
       <code class="literal">
        /
        <em class="replaceable">
         <code>
          ns
         </code>
        </em>
       </code>
       suffix
            immediately following the address.
      </p>
     </li>
     <li class="listitem">
      <p>
       An address with no
       <code class="literal">
        /
        <em class="replaceable">
         <code>
          ns
         </code>
        </em>
       </code>
       suffix
            uses the host system global namespace. The global namespace
            is therefore the default.
      </p>
     </li>
     <li class="listitem">
      <p>
       An address with a
       <code class="literal">
        /
        <em class="replaceable">
         <code>
          ns
         </code>
        </em>
       </code>
       suffix
            uses the namespace named
       <em class="replaceable">
        <code>
         ns
        </code>
       </em>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The host system must support network namespaces and each
            named namespace must previously have been set up. Naming a
            nonexistent namespace produces an error.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="link" href="server-system-variables.html#sysvar_bind_address">
        <code class="literal">
         bind_address
        </code>
       </a>
       and
       <a class="link" href="x-plugin-options-system-variables.html#sysvar_mysqlx_bind_address">
        <code class="literal">
         mysqlx_bind_address
        </code>
       </a>
       accept
            a list of multiple comma-separated addresses, the variable
            value can specify addresses in the global namespace, in
            named namespaces, or a mix.
      </p>
     </li>
    </ul>
   </div>
   <p>
    If an error occurs during server startup for attempts to use a
        namespace, the server does not start. If errors occur for
        X Plugin during plugin initialization such that it is unable to
        bind to any address, the plugin fails its initialization
        sequence and the server does not load it.
   </p>
   <p>
    On the client side, a network namespace can be specified in
        these contexts:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       For 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 and the
       <span class="command">
        <strong>
         mysqlxtest
        </strong>
       </span>
       test suite client, use the
       <a class="link" href="mysql-command-options.html#option_mysql_network-namespace">
        <code class="option">
         --network-namespace
        </code>
       </a>
       option.
            For example:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa42222649"><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">mysql <span class="token constant">--host</span><span class="token attr-value"><span class="token punctuation">=</span>192.0.2.2</span> <span class="token constant">--network-namespace</span><span class="token attr-value"><span class="token punctuation">=</span>red</span></code></pre>
      </div>
      <p>
       If the
       <a class="link" href="mysql-command-options.html#option_mysql_network-namespace">
        <code class="option">
         --network-namespace
        </code>
       </a>
       option is omitted, the connection uses the default (global)
            namespace.
      </p>
     </li>
     <li class="listitem">
      <p>
       For replication connections from replica servers to source
            servers, use the
       <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>
       statement and specify the
       <code class="literal">
        NETWORK_NAMESPACE
       </code>
       option. For example:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69766761"><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">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">'192.0.2.2'</span><span class="token punctuation">,</span>
  <span class="token keyword">NETWORK_NAMESPACE</span> <span class="token operator">=</span> <span class="token string">'red'</span><span class="token punctuation">;</span></code></pre>
      </div>
      <p>
       If the
       <code class="literal">
        NETWORK_NAMESPACE
       </code>
       option is
            omitted, replication connections use the default (global)
            namespace.
      </p>
     </li>
    </ul>
   </div>
   <p>
    The following example sets up a MySQL server that listens for
        connections in the global,
    <code class="literal">
     red
    </code>
    , and
    <code class="literal">
     blue
    </code>
    namespaces, and shows how to configure
        accounts that connect from the
    <code class="literal">
     red
    </code>
    and
    <code class="literal">
     blue
    </code>
    namespaces. It is assumed that the
    <code class="literal">
     red
    </code>
    and
    <code class="literal">
     blue
    </code>
    namespaces
        have already been created as shown in
    <a class="xref" href="network-namespace-support.html#network-namespaces-host-prerequisites" title="Host System Prerequisites">
     Host System Prerequisites
    </a>
    .
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       Configure the server to listen on addresses in multiple
            namespaces. Put these lines in the server
       <code class="filename">
        my.cnf
       </code>
       file and start the server:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa25984069"><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-ini"><span class="token selector">[mysqld]</span>
<span class="token constant">bind_address</span> <span class="token attr-value"><span class="token punctuation">=</span> 127.0.1.1,192.0.2.2/red,198.51.100.2/blue</span></code></pre>
      </div>
      <p>
       The value tells the server to listen on the loopback address
       <code class="literal">
        127.0.0.1
       </code>
       in the global namespace, the
            address
       <code class="literal">
        192.0.2.2
       </code>
       in the
       <code class="literal">
        red
       </code>
       namespace, and the address
       <code class="literal">
        198.51.100.2
       </code>
       in the
       <code class="literal">
        blue
       </code>
       namespace.
      </p>
     </li>
     <li class="listitem">
      <p>
       Connect to the server in the global namespace and create
            accounts that have permission to connect from an address in
            the address space of each named namespace:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa67139881"><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">$&gt; </span><span class="token command">mysql</span> <span class="token property">-u</span> root <span class="token property">-h</span> 127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1 <span class="token property">-p</span>
Enter password<span class="token punctuation">:</span> <em class="replaceable">root_password</em>

<span class="token prompt">mysql&gt;</span><span class="token command"> CREATE</span> USER <span class="token atrule">'red_user'</span>@<span class="token atrule">'192.0.2.2'</span>
       IDENTIFIED BY <span class="token atrule">'<em class="replaceable">red_user_password</em>'</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span><span class="token command"> CREATE</span> USER <span class="token atrule">'blue_user'</span>@<span class="token atrule">'198.51.100.2'</span>
       IDENTIFIED BY <span class="token atrule">'<em class="replaceable">blue_user_password</em>'</span><span class="token punctuation">;</span></code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       Verify that you can connect to the server in each named
            namespace:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa63667850"><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">$&gt; </span><span class="token command">mysql</span> <span class="token property">-u</span> red_user <span class="token property">-h</span> 192<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token punctuation">.</span>2 <span class="token constant">--network-namespace</span><span class="token attr-value"><span class="token punctuation">=</span>red</span> <span class="token property">-p</span>
Enter password<span class="token punctuation">:</span> <em class="replaceable">red_user_password</em>

<span class="token prompt">mysql&gt;</span><span class="token command"> SELECT</span> USER<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><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><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><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>
<span class="token output"><span class="token punctuation">|</span> USER()             <span class="token punctuation">|</span></span>
<span class="token output"><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><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><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>
<span class="token output"><span class="token punctuation">|</span> red_user@192.0.2.2 <span class="token punctuation">|</span></span>
<span class="token output"><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><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><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></code></pre>
      </div>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa92628822"><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">$&gt; </span><span class="token command">mysql</span> <span class="token property">-u</span> blue_user <span class="token property">-h</span> 198<span class="token punctuation">.</span>51<span class="token punctuation">.</span>100<span class="token punctuation">.</span>2 <span class="token constant">--network-namespace</span><span class="token attr-value"><span class="token punctuation">=</span>blue</span> <span class="token property">-p</span>
Enter password<span class="token punctuation">:</span> <em class="replaceable">blue_user_password</em>

<span class="token prompt">mysql&gt;</span><span class="token command"> SELECT</span> USER<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><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><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><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><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> USER()                 <span class="token punctuation">|</span></span>
<span class="token output"><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><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><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><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> blue_user@198.51.100.2 <span class="token punctuation">|</span></span>
<span class="token output"><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><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><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><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
      </div>
      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
       <div class="admon-title">
        Note
       </div>
       <p>
        You might see different results from
        <a class="link" href="information-functions.html#function_user">
         <code class="literal">
          USER()
         </code>
        </a>
        , which can return a
              value that includes a host name rather than an IP address
              if your DNS is configured to be able to resolve the
              address to the corresponding host name and the server is
              not run with the
        <a class="link" href="server-system-variables.html#sysvar_skip_name_resolve">
         <code class="literal">
          skip_name_resolve
         </code>
        </a>
        system
              variable enabled.
       </p>
      </div>
      <p>
       You might also try invoking
       <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
        <span class="command">
         <strong>
          mysql
         </strong>
        </span>
       </a>
       without
            the
       <a class="link" href="mysql-command-options.html#option_mysql_network-namespace">
        <code class="option">
         --network-namespace
        </code>
       </a>
       option
            to see whether the connection attempt succeeds, and, if so,
            how the
       <a class="link" href="information-functions.html#function_user">
        <code class="literal">
         USER()
        </code>
       </a>
       value is
            affected.
      </p>
     </li>
    </ol>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="network-namespaces-monitoring">
       </a>
       Network Namespace Monitoring
      </h4>
     </div>
    </div>
   </div>
   <p>
    For replication monitoring purposes, these information sources
        have a column that displays the applicable network namespace for
        connections:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       The Performance Schema
       <code class="literal">
        replication_connection_configuration
       </code>
       table. See
       <a class="xref" href="performance-schema-replication-connection-configuration-table.html" title="29.12.11.11 The replication_connection_configuration Table">
        Section 29.12.11.11, “The replication_connection_configuration Table”
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The replica server connection metadata repository. See
       <a class="xref" href="replica-logs-status.html" title="19.2.4.2 Replication Metadata Repositories">
        Section 19.2.4.2, “Replication Metadata Repositories”
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <a class="link" href="show-replica-status.html" title="15.7.7.35 SHOW REPLICA STATUS Statement">
        <code class="literal">
         SHOW
            REPLICA STATUS
        </code>
       </a>
       statement.
      </p>
     </li>
    </ul>
   </div>
  </div>
 </div>
 <br/>
</div>
