<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="multiple-windows-services">
      </a>
      7.8.2.2 Starting Multiple MySQL Instances as Windows Services
     </h4>
    </div>
   </div>
  </div>
  <p>
   On Windows, a MySQL server can run as a Windows service. The
        procedures for installing, controlling, and removing a single
        MySQL service are described in
   <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>
  <p>
   To set up multiple MySQL services, you must make sure that each
        instance uses a different service name in addition to the other
        parameters that must be unique per instance.
  </p>
  <p>
   For the following instructions, suppose that you want to run the
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   server from two different versions of
        MySQL that are installed at
   <code class="filename">
    C:\mysql-5.7.9
   </code>
   and
   <code class="filename">
    C:\mysql-8.4.3
   </code>
   ,
        respectively. (This might be the case if you are running 5.7.9
        as your production server, but also want to conduct tests using
        8.4.3.)
  </p>
  <p>
   To install MySQL as a Windows service, use the
   <code class="option">
    --install
   </code>
   or
   <code class="option">
    --install-manual
   </code>
   option. For information about these options, 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>
  <p>
   Based on the preceding information, you have several ways to set
        up multiple services. The following instructions describe some
        examples. Before trying any of them, shut down and remove any
        existing MySQL services.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <span class="bold">
       <strong>
        Approach 1:
       </strong>
      </span>
      Specify the
            options for all services in one of the standard option
            files. To do this, use a different service name for each
            server. Suppose that you want to run the 5.7.9
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      using the service name of
      <code class="literal">
       mysqld1
      </code>
      and the 8.4.3
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      using the service name
      <code class="literal">
       mysqld2
      </code>
      . In this case, you can use the
      <code class="literal">
       [mysqld1]
      </code>
      group for 5.7.9 and the
      <code class="literal">
       [mysqld2]
      </code>
      group for 8.4.3.
            For example, you can set up
      <code class="filename">
       C:\my.cnf
      </code>
      like this:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa12762797"><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 comment" spellcheck="true"># options for mysqld1 service</span>
<span class="token selector">[mysqld1]</span>
<span class="token constant">basedir</span> <span class="token attr-value"><span class="token punctuation">=</span> C:/mysql-5.7.9</span>
<span class="token constant">port</span> <span class="token attr-value"><span class="token punctuation">=</span> 3307</span>
<span class="token constant">enable-named-pipe</span>
<span class="token constant">socket</span> <span class="token attr-value"><span class="token punctuation">=</span> mypipe1</span>

<span class="token comment" spellcheck="true"># options for mysqld2 service</span>
<span class="token selector">[mysqld2]</span>
<span class="token constant">basedir</span> <span class="token attr-value"><span class="token punctuation">=</span> C:/mysql-8.4.3</span>
<span class="token constant">port</span> <span class="token attr-value"><span class="token punctuation">=</span> 3308</span>
<span class="token constant">enable-named-pipe</span>
<span class="token constant">socket</span> <span class="token attr-value"><span class="token punctuation">=</span> mypipe2</span></code></pre>
     </div>
     <p>
      Install the services as follows, using the full server path
            names to ensure that Windows registers the correct
            executable program for each service:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa95456109"><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">C:\&gt;</span><span class="token command"> C:\mysql-5.7.9\bin\mysqld</span> <span class="token property">--install</span> mysqld1
<span class="token prompt">C:\&gt;</span><span class="token command"> C:\mysql-8.4.3\bin\mysqld</span> <span class="token property">--install</span> mysqld2</code></pre>
     </div>
     <p>
      To start the services, use the services manager, or
      <span class="command">
       <strong>
        NET START
       </strong>
      </span>
      or
      <span class="command">
       <strong>
        SC START
       </strong>
      </span>
      with the appropriate service names:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa75237884"><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">C:\&gt;</span><span class="token command"> SC</span> START mysqld1
<span class="token prompt">C:\&gt;</span><span class="token command"> SC</span> START mysqld2</code></pre>
     </div>
     <p>
      To stop the services, use the services manager, or use
      <span class="command">
       <strong>
        NET STOP
       </strong>
      </span>
      or
      <span class="command">
       <strong>
        SC STOP
       </strong>
      </span>
      with the appropriate service names:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa5456928"><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">C:\&gt;</span><span class="token command"> SC</span> STOP mysqld1
<span class="token prompt">C:\&gt;</span><span class="token command"> SC</span> STOP mysqld2</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      <span class="bold">
       <strong>
        Approach 2:
       </strong>
      </span>
      Specify options
            for each server in separate files and use
      <a class="link" href="option-file-options.html#option_general_defaults-file">
       <code class="option">
        --defaults-file
       </code>
      </a>
      when you
            install the services to tell each server what file to use.
            In this case, each file should list options using a
      <code class="literal">
       [mysqld]
      </code>
      group.
     </p>
     <p>
      With this approach, to specify options for the 5.7.9
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      , create a file
      <code class="filename">
       C:\my-opts1.cnf
      </code>
      that looks like this:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa49440738"><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">basedir</span> <span class="token attr-value"><span class="token punctuation">=</span> C:/mysql-5.7.9</span>
<span class="token constant">port</span> <span class="token attr-value"><span class="token punctuation">=</span> 3307</span>
<span class="token constant">enable-named-pipe</span>
<span class="token constant">socket</span> <span class="token attr-value"><span class="token punctuation">=</span> mypipe1</span></code></pre>
     </div>
     <p>
      For the 8.4.3
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      , create
            a file
      <code class="filename">
       C:\my-opts2.cnf
      </code>
      that looks like
            this:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa28760675"><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">basedir</span> <span class="token attr-value"><span class="token punctuation">=</span> C:/mysql-8.4.3</span>
<span class="token constant">port</span> <span class="token attr-value"><span class="token punctuation">=</span> 3308</span>
<span class="token constant">enable-named-pipe</span>
<span class="token constant">socket</span> <span class="token attr-value"><span class="token punctuation">=</span> mypipe2</span></code></pre>
     </div>
     <p>
      Install the services as follows (enter each command on a
            single line):
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa25832254"><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">C:\&gt;</span><span class="token command"> C:\mysql-5.7.9\bin\mysqld</span> <span class="token property">--install</span> mysqld1
           <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>C:\my-opts1.cnf</span>
<span class="token prompt">C:\&gt;</span><span class="token command"> C:\mysql-8.4.3\bin\mysqld</span> <span class="token property">--install</span> mysqld2
           <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>C:\my-opts2.cnf</span></code></pre>
     </div>
     <p>
      When you install a MySQL server as a service and use a
      <a class="link" href="option-file-options.html#option_general_defaults-file">
       <code class="option">
        --defaults-file
       </code>
      </a>
      option, the
            service name must precede the option.
     </p>
     <p>
      After installing the services, start and stop them the same
            way as in the preceding example.
     </p>
    </li>
   </ul>
  </div>
  <p>
   To remove multiple services, use
   <span class="command">
    <strong>
     SC DELETE
     <em class="replaceable">
      <code>
       mysqld_service_name
      </code>
     </em>
    </strong>
   </span>
   for
        each one. Alternatively, use
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld --remove
     </strong>
    </span>
   </a>
   for each one, specifying a service name following the
   <a class="link" href="server-options.html#option_mysqld_remove">
    <code class="option">
     --remove
    </code>
   </a>
   option. If the service
        name is the default (
   <code class="literal">
    MySQL
   </code>
   ), you can omit it
        when using
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld --remove
     </strong>
    </span>
   </a>
   .
  </p>
 </div>
 <br/>
</div>
