<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="multiple-servers">
      </a>
      7.8 Running Multiple MySQL Instances on One Machine
     </h2>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="multiple-data-directories.html">
       7.8.1 Setting Up Multiple Data Directories
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="multiple-windows-servers.html">
       7.8.2 Running Multiple MySQL Instances on Windows
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="multiple-unix-servers.html">
       7.8.3 Running Multiple MySQL Instances on Unix
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="multiple-server-clients.html">
       7.8.4 Using Client Programs in a Multiple-Server Environment
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <a class="indexterm" name="idm46045254134944">
  </a>
  <a class="indexterm" name="idm46045254133488">
  </a>
  <a class="indexterm" name="idm46045254132416">
  </a>
  <a class="indexterm" name="idm46045254131344">
  </a>
  <a class="indexterm" name="idm46045254129856">
  </a>
  <p>
   In some cases, you might want to run multiple instances of MySQL on
    a single machine. You might want to test a new MySQL release while
    leaving an existing production setup undisturbed. Or you might want
    to give different users access to different
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   servers that they manage themselves. (For
    example, you might be an Internet Service Provider that wants to
    provide independent MySQL installations for different customers.)
  </p>
  <p>
   It is possible to use a different MySQL server binary per instance,
    or use the same binary for multiple instances, or any combination of
    the two approaches. For example, you might run a server from MySQL
    8.3 and one from MySQL 8.4, to see how
    different versions handle a given workload. Or you might run
    multiple instances of the current production version, each managing
    a different set of databases.
  </p>
  <p>
   Whether or not you use distinct server binaries, each instance that
    you run must be configured with unique values for several operating
    parameters. This eliminates the potential for conflict between
    instances. Parameters can be set on the command line, in option
    files, or by setting environment variables. See
   <a class="xref" href="program-options.html" title="6.2.2 Specifying Program Options">
    Section 6.2.2, “Specifying Program Options”
   </a>
   . To see the values used by a given
    instance, connect to it and execute a
   <a class="link" href="show-variables.html" title="15.7.7.41 SHOW VARIABLES Statement">
    <code class="literal">
     SHOW
    VARIABLES
    </code>
   </a>
   statement.
  </p>
  <p>
   The primary resource managed by a MySQL instance is the data
    directory. Each instance should use a different data directory, the
    location of which is specified using the
   <a class="link" href="server-system-variables.html#sysvar_datadir">
    <code class="option">
     --datadir=
     <em class="replaceable">
      <code>
       dir_name
      </code>
     </em>
    </code>
   </a>
   option. For methods of configuring each instance with its own data
    directory, and warnings about the dangers of failing to do so, see
   <a class="xref" href="multiple-data-directories.html" title="7.8.1 Setting Up Multiple Data Directories">
    Section 7.8.1, “Setting Up Multiple Data Directories”
   </a>
   .
  </p>
  <p>
   In addition to using different data directories, several other
    options must have different values for each server instance:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="server-options.html#option_mysqld_port">
       <code class="option">
        --port=
        <em class="replaceable">
         <code>
          port_num
         </code>
        </em>
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045254117264">
     </a>
     <p>
      <a class="link" href="server-options.html#option_mysqld_port">
       <code class="option">
        --port
       </code>
      </a>
      controls the port number
        for TCP/IP connections. Alternatively, if the host has multiple
        network addresses, you can set the
      <a class="link" href="server-system-variables.html#sysvar_bind_address">
       <code class="literal">
        bind_address
       </code>
      </a>
      system variable to
        cause each server to listen to a different address.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="server-options.html#option_mysqld_socket">
       <code class="option">
        --socket={
        <em class="replaceable">
         <code>
          file_name
         </code>
        </em>
        |
        <em class="replaceable">
         <code>
          pipe_name
         </code>
        </em>
        }
       </code>
      </a>
     </p>
     <p>
      <a class="link" href="server-options.html#option_mysqld_socket">
       <code class="option">
        --socket
       </code>
      </a>
      controls the Unix socket
        file path on Unix or the named-pipe name on Windows. On Windows,
        it is necessary to specify distinct pipe names only for those
        servers configured to permit named-pipe connections.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="server-system-variables.html#sysvar_shared_memory_base_name">
       <code class="option">
        --shared-memory-base-name=
        <em class="replaceable">
         <code>
          name
         </code>
        </em>
       </code>
      </a>
     </p>
     <p>
      This option is used only on Windows. It designates the
        shared-memory name used by a Windows server to permit clients to
        connect using shared memory. It is necessary to specify distinct
        shared-memory names only for those servers configured to permit
        shared-memory connections.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="server-system-variables.html#sysvar_pid_file">
       <code class="option">
        --pid-file=
        <em class="replaceable">
         <code>
          file_name
         </code>
        </em>
       </code>
      </a>
     </p>
     <p>
      This option indicates the path name of the file in which the
        server writes its process ID.
     </p>
    </li>
   </ul>
  </div>
  <p>
   If you use the following log file options, their values must differ
    for each server:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="server-system-variables.html#sysvar_general_log_file">
       <code class="option">
        --general_log_file=
        <em class="replaceable">
         <code>
          file_name
         </code>
        </em>
       </code>
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="replication-options-binary-log.html#option_mysqld_log-bin">
       <code class="option">
        --log-bin[=
        <em class="replaceable">
         <code>
          file_name
         </code>
        </em>
        ]
       </code>
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="server-system-variables.html#sysvar_slow_query_log_file">
       <code class="option">
        --slow_query_log_file=
        <em class="replaceable">
         <code>
          file_name
         </code>
        </em>
       </code>
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="server-options.html#option_mysqld_log-error">
       <code class="option">
        --log-error[=
        <em class="replaceable">
         <code>
          file_name
         </code>
        </em>
        ]
       </code>
      </a>
     </p>
    </li>
   </ul>
  </div>
  <p>
   For further discussion of log file options, see
   <a class="xref" href="server-logs.html" title="7.4 MySQL Server Logs">
    Section 7.4, “MySQL Server Logs”
   </a>
   .
  </p>
  <p>
   To achieve better performance, you can specify the following option
    differently for each server, to spread the load between several
    physical disks:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="server-options.html#option_mysqld_tmpdir">
       <code class="option">
        --tmpdir=
        <em class="replaceable">
         <code>
          dir_name
         </code>
        </em>
       </code>
      </a>
     </p>
    </li>
   </ul>
  </div>
  <p>
   Having different temporary directories also makes it easier to
    determine which MySQL server created any given temporary file.
  </p>
  <p>
   If you have multiple MySQL installations in different locations, you
    can specify the base directory for each installation with the
   <a class="link" href="server-system-variables.html#sysvar_basedir">
    <code class="option">
     --basedir=
     <em class="replaceable">
      <code>
       dir_name
      </code>
     </em>
    </code>
   </a>
   option. This causes each instance to automatically use a different
    data directory, log files, and PID file because the default for each
    of those parameters is relative to the base directory. In that case,
    the only other options you need to specify are the
   <a class="link" href="server-options.html#option_mysqld_socket">
    <code class="option">
     --socket
    </code>
   </a>
   and
   <a class="link" href="server-options.html#option_mysqld_port">
    <code class="option">
     --port
    </code>
   </a>
   options. Suppose that you
    install different versions of MySQL using
   <code class="filename">
    tar
   </code>
   file binary distributions. These install in different locations, so
    you can start the server for each installation using the command
   <span class="command">
    <strong>
     bin/mysqld_safe
    </strong>
   </span>
   under its corresponding base
    directory.
   <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>
   determines the proper
   <a class="link" href="server-system-variables.html#sysvar_basedir">
    <code class="option">
     --basedir
    </code>
   </a>
   option to pass to
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   , and you need specify only the
   <a class="link" href="mysqld-safe.html#option_mysqld_safe_socket">
    <code class="option">
     --socket
    </code>
   </a>
   and
   <a class="link" href="mysqld-safe.html#option_mysqld_safe_port">
    <code class="option">
     --port
    </code>
   </a>
   options 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>
   .
  </p>
  <p>
   As discussed in the following sections, it is possible to start
    additional servers by specifying appropriate command options or by
    setting environment variables. However, if you need to run multiple
    servers on a more permanent basis, it is more convenient to use
    option files to specify for each server those option values that
    must be unique to it. The
   <a class="link" href="option-file-options.html#option_general_defaults-file">
    <code class="option">
     --defaults-file
    </code>
   </a>
   option is useful for
    this purpose.
  </p>
 </div>
 <br/>
</div>
