<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="mysql-server">
      </a>
      6.3.3 mysql.server — MySQL Server Startup Script
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045321380048">
  </a>
  <p>
   MySQL distributions on Unix and Unix-like system include a
        script named
   <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>
   , which starts the
        MySQL server using
   <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>
   . It can be
        used on systems such as Linux and Solaris that use System
        V-style run directories to start and stop system services. It is
        also used by the macOS Startup Item for MySQL.
  </p>
  <p>
   <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>
   is the script name as used
        within the MySQL source tree. The installed name might be
        different (for example,
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   or
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   ). In the following discussion, adjust
        the name
   <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>
   as appropriate for your
        system.
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    For some Linux platforms, MySQL installation from RPM or
          Debian packages includes systemd support for managing MySQL
          server startup and shutdown. On these platforms,
    <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
    <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>
    are not installed because they
          are unnecessary. For more information, 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>
  </div>
  <p>
   To start or stop the server manually using 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, invoke it from the
        command line with
   <code class="literal">
    start
   </code>
   or
   <code class="literal">
    stop
   </code>
   arguments:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa10726051"><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 punctuation">.</span>server start
mysql<span class="token punctuation">.</span>server stop</code></pre>
  </div>
  <p>
   <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>
   changes location to the MySQL
        installation directory, then invokes
   <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 run the server as some
        specific user, add an appropriate
   <code class="literal">
    user
   </code>
   option
        to the
   <code class="literal">
    [mysqld]
   </code>
   group of the global
   <code class="filename">
    /etc/my.cnf
   </code>
   option file, as shown later in
        this section. (It is possible that you must edit
   <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>
   if you've installed a binary
        distribution of MySQL in a nonstandard location. Modify it to
        change location into the proper directory before it runs
   <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>
   . If you do this, your modified
        version of
   <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>
   may be overwritten if
        you upgrade MySQL in the future; make a copy of your edited
        version that you can reinstall.)
  </p>
  <p>
   <a class="link" href="mysql-server.html" title="6.3.3 mysql.server — MySQL Server Startup Script">
    <span class="command">
     <strong>
      mysql.server stop
     </strong>
    </span>
   </a>
   stops the server by sending
        a signal to it. You can also stop the server manually by
        executing
   <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
    <span class="command">
     <strong>
      mysqladmin shutdown
     </strong>
    </span>
   </a>
   .
  </p>
  <p>
   To start and stop MySQL automatically on your server, you must
        add start and stop commands to the appropriate places in your
   <code class="filename">
    /etc/rc*
   </code>
   files:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      If you use the Linux server RPM package
            (
      <code class="literal">
       MySQL-server-
       <em class="replaceable">
        <code>
         VERSION
        </code>
       </em>
       .rpm
      </code>
      ),
            or a native Linux package installation, 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 may be installed in
            the
      <code class="filename">
       /etc/init.d
      </code>
      directory with the name
      <code class="filename">
       mysqld
      </code>
      or
      <code class="filename">
       mysql
      </code>
      .
            See
      <a class="xref" href="linux-installation-rpm.html" title="2.5.4 Installing MySQL on Linux Using RPM Packages from Oracle">
       Section 2.5.4, “Installing MySQL on Linux Using RPM Packages from Oracle”
      </a>
      , for more
            information on the Linux RPM packages.
     </p>
    </li>
    <li class="listitem">
     <p>
      If you install MySQL from a source distribution or using a
            binary distribution format that does not install
      <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>
      automatically, you can
            install the script manually. It can be found in the
      <code class="filename">
       support-files
      </code>
      directory under the MySQL
            installation directory or in a MySQL source tree. Copy the
            script to the
      <code class="filename">
       /etc/init.d
      </code>
      directory
            with the name
      <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
       <span class="command">
        <strong>
         mysql
        </strong>
       </span>
      </a>
      and make it
            executable:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa82236114"><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">cp mysql<span class="token punctuation">.</span>server /etc/init<span class="token punctuation">.</span>d/mysql
chmod +x /etc/init<span class="token punctuation">.</span>d/mysql</code></pre>
     </div>
     <p>
      After installing the script, the commands needed to activate
            it to run at system startup depend on your operating system.
            On Linux, you can use
      <span class="command">
       <strong>
        chkconfig
       </strong>
      </span>
      :
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa151143"><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">chkconfig <span class="token property">--add</span> mysql</code></pre>
     </div>
     <p>
      On some Linux systems, the following command also seems to
            be necessary to fully enable 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>
      script:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa68790989"><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">chkconfig <span class="token property">--level</span> 345 mysql on</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      On FreeBSD, startup scripts generally should go in
      <code class="filename">
       /usr/local/etc/rc.d/
      </code>
      . Install the
      <code class="filename">
       mysql.server
      </code>
      script as
      <code class="filename">
       /usr/local/etc/rc.d/mysql.server.sh
      </code>
      to
            enable automatic startup. The
      <code class="literal">
       rc(8)
      </code>
      manual page states that scripts in this directory are
            executed only if their base name matches the
      <code class="literal">
       *.sh
      </code>
      shell file name pattern. Any other
            files or directories present within the directory are
            silently ignored.
     </p>
    </li>
    <li class="listitem">
     <p>
      As an alternative to the preceding setup, some operating
            systems also use
      <code class="filename">
       /etc/rc.local
      </code>
      or
      <code class="filename">
       /etc/init.d/boot.local
      </code>
      to start
            additional services on startup. To start up MySQL using this
            method, append a command like the one following to the
            appropriate startup file:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa94339744"><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">/bin/sh <span class="token property">-c</span> <span class="token atrule">'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &amp;'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      For other systems, consult your operating system
            documentation to see how to install startup scripts.
     </p>
    </li>
   </ul>
  </div>
  <p>
   <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>
   reads options from the
   <code class="literal">
    [mysql.server]
   </code>
   and
   <code class="literal">
    [mysqld]
   </code>
   sections of option files. For
        backward compatibility, it also reads
   <code class="literal">
    [mysql_server]
   </code>
   sections, but to be current
        you should rename such sections to
   <code class="literal">
    [mysql.server]
   </code>
   .
  </p>
  <a class="indexterm" name="idm46045321316912">
  </a>
  <p>
   You can add options for
   <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>
   in a
        global
   <code class="filename">
    /etc/my.cnf
   </code>
   file. A typical
   <code class="filename">
    my.cnf
   </code>
   file might look like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa91772350"><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">datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql/var</span>
<span class="token constant">socket</span><span class="token attr-value"><span class="token punctuation">=</span>/var/tmp/mysql.sock</span>
<span class="token constant">port</span><span class="token attr-value"><span class="token punctuation">=</span>3306</span>
<span class="token constant">user</span><span class="token attr-value"><span class="token punctuation">=</span>mysql</span>

<span class="token selector">[mysql.server]</span>
<span class="token constant">basedir</span><span class="token attr-value"><span class="token punctuation">=</span>/usr/local/mysql</span></code></pre>
  </div>
  <p>
   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 supports the options
        shown in the following table. If specified, they
   <span class="emphasis">
    <em>
     must
    </em>
   </span>
   be placed in an option file, not on
        the command line.
   <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>
   supports only
   <code class="literal">
    start
   </code>
   and
   <code class="literal">
    stop
   </code>
   as
        command-line arguments.
  </p>
  <div class="table">
   <a name="idm46045321306320">
   </a>
   <p class="title">
    <b>
     Table 6.8 mysql.server Option-File Options
    </b>
   </p>
   <div class="table-contents">
    <table frame="box" rules="all" summary="Option-file options available for mysql.server.">
     <colgroup>
      <col align="left" style="width: 20%"/>
      <col align="left" style="width: 70%"/>
      <col align="left" style="width: 10%"/>
     </colgroup>
     <thead>
      <tr>
       <th scope="col">
        Option Name
       </th>
       <th scope="col">
        Description
       </th>
       <th scope="col">
        Type
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <th scope="row">
        <a class="link" href="mysql-server.html#option_mysql_server_basedir">
         <code class="literal">
          basedir
         </code>
        </a>
       </th>
       <td>
        Path to MySQL installation directory
       </td>
       <td>
        Directory name
       </td>
      </tr>
      <tr>
       <th scope="row">
        <a class="link" href="mysql-server.html#option_mysql_server_datadir">
         <code class="literal">
          datadir
         </code>
        </a>
       </th>
       <td>
        Path to MySQL data directory
       </td>
       <td>
        Directory name
       </td>
      </tr>
      <tr>
       <th scope="row">
        <a class="link" href="mysql-server.html#option_mysql_server_pid-file">
         <code class="literal">
          pid-file
         </code>
        </a>
       </th>
       <td>
        File in which server should write its process ID
       </td>
       <td>
        File name
       </td>
      </tr>
      <tr>
       <th scope="row">
        <a class="link" href="mysql-server.html#option_mysql_server_service-startup-timeout">
         <code class="literal">
          service-startup-timeout
         </code>
        </a>
       </th>
       <td>
        How long to wait for server startup
       </td>
       <td>
        Integer
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a name="option_mysql_server_basedir">
      </a>
      <a class="link" href="mysql-server.html#option_mysql_server_basedir">
       <code class="option">
        basedir=
        <em class="replaceable">
         <code>
          dir_name
         </code>
        </em>
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045321277424">
     </a>
     <a class="indexterm" name="idm46045321275936">
     </a>
     <p>
      The path to the MySQL installation directory.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="option_mysql_server_datadir">
      </a>
      <a class="link" href="mysql-server.html#option_mysql_server_datadir">
       <code class="option">
        datadir=
        <em class="replaceable">
         <code>
          dir_name
         </code>
        </em>
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045321271568">
     </a>
     <a class="indexterm" name="idm46045321270080">
     </a>
     <p>
      The path to the MySQL data directory.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="option_mysql_server_pid-file">
      </a>
      <a class="link" href="mysql-server.html#option_mysql_server_pid-file">
       <code class="option">
        pid-file=
        <em class="replaceable">
         <code>
          file_name
         </code>
        </em>
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045321265648">
     </a>
     <a class="indexterm" name="idm46045321264160">
     </a>
     <p>
      The path name of the file in which the server should write
            its process ID. The server creates the file in the data
            directory unless an absolute path name is given to specify a
            different directory.
     </p>
     <p>
      If this option is not given,
      <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>
      uses a default value of
      <code class="filename">
       <em class="replaceable">
        <code>
         host_name
        </code>
       </em>
       .pid
      </code>
      .
            The PID file value passed to
      <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>
      overrides any value specified in the
      <code class="literal">
       [mysqld_safe]
      </code>
      option file group. Because
      <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>
      reads the
      <code class="literal">
       [mysqld]
      </code>
      option file group but not the
      <code class="literal">
       [mysqld_safe]
      </code>
      group, you can ensure that
      <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>
      gets the same value when
            invoked from
      <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>
      as when invoked
            manually by putting the same
      <code class="literal">
       pid-file
      </code>
      setting in both the
      <code class="literal">
       [mysqld_safe]
      </code>
      and
      <code class="literal">
       [mysqld]
      </code>
      groups.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a name="option_mysql_server_service-startup-timeout">
      </a>
      <a class="link" href="mysql-server.html#option_mysql_server_service-startup-timeout">
       <code class="option">
        service-startup-timeout=
        <em class="replaceable">
         <code>
          seconds
         </code>
        </em>
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045321247200">
     </a>
     <a class="indexterm" name="idm46045321245696">
     </a>
     <p>
      How long in seconds to wait for confirmation of server
            startup. If the server does not start within this time,
      <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>
      exits with an error. The
            default value is 900. A value of 0 means not to wait at all
            for startup. Negative values mean to wait forever (no
            timeout).
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
