<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="restart">
      </a>
      15.7.8.8 RESTART Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045168295136">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa69717273"><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">RESTART</span></code></pre>
  </div>
  <p>
   This statement stops and restarts the MySQL server. It requires
        the
   <a class="link" href="privileges-provided.html#priv_shutdown">
    <code class="literal">
     SHUTDOWN
    </code>
   </a>
   privilege.
  </p>
  <p>
   One use for
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   is when it is
        not possible or convenient to gain command-line access to the
        MySQL server on the server host to restart it. For example,
   <a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
    <code class="literal">
     SET
        PERSIST_ONLY
    </code>
   </a>
   can be used at runtime to make
        configuration changes to system variables that can be set only
        at server startup, but the server must still be restarted for
        those changes to take effect. The
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   statement provides a way
        to do so from within client sessions, without requiring
        command-line access on the server host.
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    After executing a
    <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
     <code class="literal">
      RESTART
     </code>
    </a>
    statement, the client can expect the current connection to be
          lost. If auto-reconnect is enabled, the connection is
          reestablished after the server restarts. Otherwise, the
          connection must be reestablished manually.
   </p>
  </div>
  <p>
   A successful
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   operation
        requires
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   to be running in an
        environment that has a monitoring process available to detect a
        server shutdown performed for restart purposes:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      In the presence of a monitoring process,
      <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
       <code class="literal">
        RESTART
       </code>
      </a>
      causes
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      to terminate such that the
            monitoring process can determine that it should start a new
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      instance.
     </p>
    </li>
    <li class="listitem">
     <p>
      If no monitoring process is present,
      <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
       <code class="literal">
        RESTART
       </code>
      </a>
      fails with an error.
     </p>
    </li>
   </ul>
  </div>
  <p>
   These platforms provide the necessary monitoring support for the
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   statement:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Windows, when
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      is started as a
            Windows service or standalone. (
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      forks, and one process acts as a monitor to the other, which
            acts as the server.)
     </p>
    </li>
    <li class="listitem">
     <p>
      Unix and Unix-like systems that use systemd or
      <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script">
       <span class="command">
        <strong>
         mysqld_safe
        </strong>
       </span>
      </a>
      to manage
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   To configure a monitoring environment such that
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   enables the
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   statement:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Set the
      <code class="literal">
       MYSQLD_PARENT_PID
      </code>
      environment
            variable to the value of the process ID of the process that
            starts
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      , before starting
      <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>
      When
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      performs a shutdown due to
            use of the
      <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
       <code class="literal">
        RESTART
       </code>
      </a>
      statement,
            it returns exit code 16.
     </p>
    </li>
    <li class="listitem">
     <p>
      When the monitoring process detects an exit code of 16, it
            starts
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      again. Otherwise, it exits.
     </p>
    </li>
   </ol>
  </div>
  <p>
   Here is a minimal example as implemented in the
   <span class="command">
    <strong>
     bash
    </strong>
   </span>
   shell:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa5682772"><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 comment" spellcheck="true">#!/bin/bash</span>

export MYSQLD_PARENT_PID<span class="token attr-value"><span class="token punctuation">=</span>$$</span>

export MYSQLD_RESTART_EXIT<span class="token attr-value"><span class="token punctuation">=</span>16</span>

while true <span class="token punctuation">;</span> do
  bin/mysqld <em class="replaceable">mysqld options here</em>
  if <span class="token punctuation">[</span> $? <span class="token property">-ne</span> $MYSQLD_RESTART_EXIT <span class="token punctuation">]</span><span class="token punctuation">;</span> then
    break
  fi
done</code></pre>
  </div>
  <p>
   On Windows, the forking used to implement
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   makes determining the
        server process to attach to for debugging more difficult. To
        alleviate this, starting the server with
   <a class="link" href="server-options.html#option_mysqld_gdb">
    <code class="option">
     --gdb
    </code>
   </a>
   suppresses forking, in
        addition to its other actions done to set up a debugging
        environment. In non-debug settings,
   <a class="link" href="server-options.html#option_mysqld_no-monitor">
    <code class="option">
     --no-monitor
    </code>
   </a>
   may be used for the
        sole purpose of suppressing forking the monitor process. For a
        server started with either
   <a class="link" href="server-options.html#option_mysqld_gdb">
    <code class="option">
     --gdb
    </code>
   </a>
   or
   <a class="link" href="server-options.html#option_mysqld_no-monitor">
    <code class="option">
     --no-monitor
    </code>
   </a>
   , executing
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   causes the server to
        simply exit without restarting.
  </p>
  <p>
   The
   <a class="link" href="server-status-variables.html#statvar_Com_xxx">
    <code class="literal">
     Com_restart
    </code>
   </a>
   status variable tracks the number of
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   statements. Because
        status variables are initialized for each server startup and do
        not persist across restarts,
   <code class="literal">
    Com_restart
   </code>
   normally has a value of zero, but can be nonzero if
   <a class="link" href="restart.html" title="15.7.8.8 RESTART Statement">
    <code class="literal">
     RESTART
    </code>
   </a>
   statements were executed
        but failed.
  </p>
 </div>
 <br/>
</div>
