<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="automatic-start">
      </a>
      2.9.5 Starting and Stopping MySQL Automatically
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045326593440">
  </a>
  <a class="indexterm" name="idm46045326591968">
  </a>
  <a class="indexterm" name="idm46045326590480">
  </a>
  <p>
   This section discusses methods for starting and stopping the MySQL
      server.
  </p>
  <p>
   Generally, you start the
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   server in one
      of these ways:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Invoke
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      directly. This works on any
          platform.
     </p>
    </li>
    <li class="listitem">
     <p>
      On Windows, you can set up a MySQL service that runs
          automatically when Windows starts. See
      <a class="xref" href="windows-start-service.html" title="2.3.3.8 Starting MySQL as a Windows Service">
       Section 2.3.3.8, “Starting MySQL as a Windows Service”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      On Unix and Unix-like systems, you can invoke
      <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>
      , which tries to determine the
          proper options for
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      and then runs it
          with those options. See
      <a class="xref" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script">
       Section 6.3.2, “mysqld_safe — MySQL Server Startup Script”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      On Linux systems that support systemd, you can use it to
          control the server. See
      <a class="xref" href="using-systemd.html" title="2.5.9 Managing MySQL Server with systemd">
       Section 2.5.9, “Managing MySQL Server with systemd”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      On systems that use System V-style run directories (that is,
      <code class="filename">
       /etc/init.d
      </code>
      and run-level specific
          directories), invoke
      <a class="link" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
       <span class="command">
        <strong>
         mysql.server
        </strong>
       </span>
      </a>
      . This
          script is used primarily at system startup and shutdown. It
          usually is installed under the name
      <code class="literal">
       mysql
      </code>
      .
          The
      <a class="link" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
       <span class="command">
        <strong>
         mysql.server
        </strong>
       </span>
      </a>
      script starts the server
          by invoking
      <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>
      . See
      <a class="xref" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
       Section 6.3.3, “mysql.server — MySQL Server Startup Script”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      On macOS, install a launchd daemon to enable automatic MySQL
          startup at system startup. The daemon starts the server by
          invoking
      <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>
      . For details, see
      <a class="xref" href="macos-installation-launchd.html" title="2.4.3 Installing and Using the MySQL Launch Daemon">
       Section 2.4.3, “Installing and Using the MySQL Launch Daemon”
      </a>
      . A MySQL
          Preference Pane also provides control for starting and
          stopping MySQL through the System Preferences. See
      <a class="xref" href="macos-installation-prefpane.html" title="2.4.4 Installing and Using the MySQL Preference Pane">
       Section 2.4.4, “Installing and Using the MySQL Preference Pane”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      On Solaris, use the service management framework (SMF) system
          to initiate and control MySQL startup.
     </p>
    </li>
   </ul>
  </div>
  <p>
   systemd, the
   <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>
   and
   <a class="link" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
    <span class="command">
     <strong>
      mysql.server
     </strong>
    </span>
   </a>
   scripts, Solaris SMF, and the
      macOS Startup Item (or MySQL Preference Pane) can be used to start
      the server manually, or automatically at system startup time.
      systemd,
   <a class="link" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
    <span class="command">
     <strong>
      mysql.server
     </strong>
    </span>
   </a>
   , and the Startup Item
      also can be used to stop the server.
  </p>
  <p>
   The following table shows which option groups the server and
      startup scripts read from option files.
  </p>
  <div class="table">
   <a name="startup-scripts-server-option-groups">
   </a>
   <p class="title">
    <b>
     Table 2.14 MySQL Startup Scripts and Supported Server Option Groups
    </b>
   </p>
   <div class="table-contents">
    <table summary="MySQL startup scripts and the server option groups they support.">
     <colgroup>
      <col style="width: 20%"/>
      <col style="width: 80%"/>
     </colgroup>
     <thead>
      <tr>
       <th>
        Script
       </th>
       <th>
        Option Groups
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <td>
        <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
         <span class="command">
          <strong>
           mysqld
          </strong>
         </span>
        </a>
       </td>
       <td>
        <code class="literal">
         [mysqld]
        </code>
        ,
        <code class="literal">
         [server]
        </code>
        ,
        <code class="literal">
         [mysqld-
         <em class="replaceable">
          <code>
           major_version
          </code>
         </em>
         ]
        </code>
       </td>
      </tr>
      <tr>
       <td>
        <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>
       </td>
       <td>
        <code class="literal">
         [mysqld]
        </code>
        ,
        <code class="literal">
         [server]
        </code>
        ,
        <code class="literal">
         [mysqld_safe]
        </code>
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
         <span class="command">
          <strong>
           mysql.server
          </strong>
         </span>
        </a>
       </td>
       <td>
        <code class="literal">
         [mysqld]
        </code>
        ,
        <code class="literal">
         [mysql.server]
        </code>
        ,
        <code class="literal">
         [server]
        </code>
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <p>
   <code class="literal">
    [mysqld-
    <em class="replaceable">
     <code>
      major_version
     </code>
    </em>
    ]
   </code>
   means that groups with names like
   <code class="literal">
    [mysqld-8.3]
   </code>
   and
   <code class="literal">
    [mysqld-8.4]
   </code>
   are read by servers
      having versions 8.3.x, 8.4.x, and so
      forth. This feature can be used to specify options that can be
      read only by servers within a given release series.
  </p>
  <p>
   For backward compatibility,
   <a class="link" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
    <span class="command">
     <strong>
      mysql.server
     </strong>
    </span>
   </a>
   also
      reads the
   <code class="literal">
    [mysql_server]
   </code>
   group and
   <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>
   also reads the
   <code class="literal">
    [safe_mysqld]
   </code>
   group. To be current, you should
      update your option files to use the
   <code class="literal">
    [mysql.server]
   </code>
   and
   <code class="literal">
    [mysqld_safe]
   </code>
   groups instead.
  </p>
  <p>
   For more information on MySQL configuration files and their
      structure and contents, see
   <a class="xref" href="option-files.html" title="6.2.2.2 Using Option Files">
    Section 6.2.2.2, “Using Option Files”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
