### 4.3.4 mysqld\_multi — Manage Multiple MySQL Servers

[]()[]()[]()[]()

[**mysqld\_multi**](mysqld-multi.html) is designed to manage several [**mysqld**](mysqld.html) processes that listen for connections on different Unix socket files and TCP/IP ports. It can start or stop servers, or report their current status.

Note

 For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, [**mysqld\_multi**](mysqld-multi.html) is not installed because it is unnecessary. For information about using systemd to handle multiple MySQL instances, see [Section 2.5.9, “Managing MySQL Server with systemd”](using-systemd.html).

[**mysqld\_multi**](mysqld-multi.html) searches for groups named `[mysqld*`N`*]` in `my.cnf` (or in the file named by the [`--defaults-file`](mysqld-multi.html#option_mysqld_multi_defaults-file) option). *`N`* can be any positive integer. This number is referred to in the following discussion as the option group number, or *`GNR`*. Group numbers distinguish option groups from one another and are used as arguments to [**mysqld\_multi**](mysqld-multi.html) to specify which servers you want to start, stop, or obtain a status report for. Options listed in these groups are the same that you would use in the `[mysqld]` group used for starting [**mysqld**](mysqld.html). (See, for example, [Section 2.10.5, “Starting and Stopping MySQL Automatically”](automatic-start.html).) However, when using multiple servers, it is necessary that each one use its own value for options such as the Unix socket file and TCP/IP port number. For more information on which options must be unique per server in a multiple-server environment, see [Section 5.8, “Running Multiple MySQL Instances on One Machine”](multiple-servers.html).

 To invoke [**mysqld\_multi**](mysqld-multi.html), use the following syntax:

```
mysqld_multi [options] {start|stop|reload|report} [GNR[,GNR] ...]
```

`start`, `stop`, `reload` (stop and restart), and `report` indicate which operation to perform. You can perform the designated operation for a single server or multiple servers, depending on the *`GNR`* list that follows the option name. If there is no list, [**mysqld\_multi**](mysqld-multi.html) performs the operation for all servers in the option file.

 Each *`GNR`* value represents an option group number or range of group numbers. The value should be the number at the end of the group name in the option file. For example, the *`GNR`* for a group named `[mysqld17]` is `17`. To specify a range of numbers, separate the first and last numbers by a dash. The *`GNR`* value `10-13` represents groups `[mysqld10]` through `[mysqld13]`. Multiple groups or group ranges can be specified on the command line, separated by commas. There must be no whitespace characters (spaces or tabs) in the *`GNR`* list; anything after a whitespace character is ignored.

 This command starts a single server using option group `[mysqld17]`:

```
mysqld_multi start 17
```

 This command stops several servers, using option groups `[mysqld8]` and `[mysqld10]` through `[mysqld13]`:

```
mysqld_multi stop 8,10-13
```

 For an example of how you might set up an option file, use this command:

```
mysqld_multi --example
```

[**mysqld\_multi**](mysqld-multi.html) searches for option files as follows:

* []() With [`--no-defaults`](mysqld-multi.html#option_mysqld_multi_no-defaults), no option files are read.

  []()[]()
* []() With [`--defaults-file=*`file_name`*`](mysqld-multi.html#option_mysqld_multi_defaults-file), only the named file is read.

  []()[]()
* []() Otherwise, option files in the standard list of locations are read, including any file named by the [`--defaults-extra-file=*`file_name`*`](mysqld-multi.html#option_mysqld_multi_defaults-extra-file) option, if one is given. (If the option is given multiple times, the last value is used.)

  []()[]()

 For additional information about these and other option-file options, see [Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”](option-file-options.html).

 Option files read are searched for `[mysqld_multi]` and `[mysqld*`N`*]` option groups. The `[mysqld_multi]` group can be used for options to [**mysqld\_multi**](mysqld-multi.html) itself. `[mysqld*`N`*]` groups can be used for options passed to specific [**mysqld**](mysqld.html) instances.

 The `[mysqld]` or `[mysqld_safe]` groups can be used for common options read by all instances of [**mysqld**](mysqld.html) or [**mysqld\_safe**](mysqld-safe.html). You can specify a [`--defaults-file=*`file_name`*`](server-options.html#option_mysqld_defaults-file) option to use a different configuration file for that instance, in which case the `[mysqld]` or `[mysqld_safe]` groups from that file are used for that instance.

[**mysqld\_multi**](mysqld-multi.html) supports the following options.

* []() [`--help`](mysqld-multi.html#option_mysqld_multi_help)

  []()[]()

   Display a help message and exit.

* []() [`--example`](mysqld-multi.html#option_mysqld_multi_example)

  []()[]()

   Display a sample option file.

* []() [`--log=*`file_name`*`](mysqld-multi.html#option_mysqld_multi_log)

  []()[]()

   Specify the name of the log file. If the file exists, log output is appended to it.

* []() [`--mysqladmin=*`prog_name`*`](mysqld-multi.html#option_mysqld_multi_mysqladmin)

  []()[]()

   The [**mysqladmin**](mysqladmin.html) binary to be used to stop servers.

* []() [`--mysqld=*`prog_name`*`](mysqld-multi.html#option_mysqld_multi_mysqld)

  []()[]()

   The [**mysqld**](mysqld.html) binary to be used. Note that you can specify [**mysqld\_safe**](mysqld-safe.html) as the value for this option also. If you use [**mysqld\_safe**](mysqld-safe.html) to start the server, you can include the `mysqld` or `ledir` options in the corresponding `[mysqld*`N`*]` option group. These options indicate the name of the server that [**mysqld\_safe**](mysqld-safe.html) should start and the path name of the directory where the server is located. (See the descriptions for these options in [Section 4.3.2, “mysqld\_safe — MySQL Server Startup Script”](mysqld-safe.html).) Example:

  ```
  [mysqld38]
  mysqld = mysqld-debug
  ledir  = /opt/local/mysql/libexec
  ```

* []() [`--no-log`](mysqld-multi.html#option_mysqld_multi_no-log)

  []()[]()

   Print log information to `stdout` rather than to the log file. By default, output goes to the log file.

* []() [`--password=*`password`*`](mysqld-multi.html#option_mysqld_multi_password)

  []()[]()

   The password of the MySQL account to use when invoking [**mysqladmin**](mysqladmin.html). Note that the password value is not optional for this option, unlike for other MySQL programs.

* []() [`--silent`](mysqld-multi.html#option_mysqld_multi_silent)

  []()[]()

   Silent mode; disable warnings.

* []() [`--tcp-ip`](mysqld-multi.html#option_mysqld_multi_tcp-ip)

  []()[]()

   Connect to each MySQL server through the TCP/IP port instead of the Unix socket file. (If a socket file is missing, the server might still be running, but accessible only through the TCP/IP port.) By default, connections are made using the Unix socket file. This option affects `stop` and `report` operations.

* []() [`--user=*`user_name`*`](mysqld-multi.html#option_mysqld_multi_user)

  []()[]()

   The user name of the MySQL account to use when invoking [**mysqladmin**](mysqladmin.html).

* []() [`--verbose`](mysqld-multi.html#option_mysqld_multi_verbose)

  []()[]()

   Be more verbose.

* []() [`--version`](mysqld-multi.html#option_mysqld_multi_version)

  []()[]()

   Display version information and exit.

 Some notes about [**mysqld\_multi**](mysqld-multi.html):

* **Most important**: Before using [**mysqld\_multi**](mysqld-multi.html) be sure that you understand the meanings of the options that are passed to the [**mysqld**](mysqld.html) servers and *why* you would want to have separate [**mysqld**](mysqld.html) processes. Beware of the dangers of using multiple [**mysqld**](mysqld.html) servers with the same data directory. Use separate data directories, unless you *know* what you are doing. Starting multiple servers with the same data directory does *not* give you extra performance in a threaded system. See [Section 5.8, “Running Multiple MySQL Instances on One Machine”](multiple-servers.html).

  Important

   Make sure that the data directory for each server is fully accessible to the Unix account that the specific [**mysqld**](mysqld.html) process is started as. *Do not* use the Unix *`root`* account for this, unless you *know* what you are doing. See [Section 6.1.5, “How to Run MySQL as a Normal User”](changing-mysql-user.html).

* Make sure that the MySQL account used for stopping the [**mysqld**](mysqld.html) servers (with the [**mysqladmin**](mysqladmin.html) program) has the same user name and password for each server. Also, make sure that the account has the [`SHUTDOWN`](privileges-provided.html#priv_shutdown) privilege. If the servers that you want to manage have different user names or passwords for the administrative accounts, you might want to create an account on each server that has the same user name and password. For example, you might set up a common `multi_admin` account by executing the following commands for each server:

  ```
  $> mysql -u root -S /tmp/mysql.sock -p
  Enter password:
  mysql> CREATE USER 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';
  mysql> GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost';
  ```

   See [Section 6.2, “Access Control and Account Management”](access-control.html). You have to do this for each [**mysqld**](mysqld.html) server. Change the connection parameters appropriately when connecting to each one. Note that the host name part of the account name must permit you to connect as `multi_admin` from the host where you want to run [**mysqld\_multi**](mysqld-multi.html).

* The Unix socket file and the TCP/IP port number must be different for every [**mysqld**](mysqld.html). (Alternatively, if the host has multiple network addresses, you can set the [`bind_address`](server-system-variables.html#sysvar_bind_address) system variable to cause different servers to listen to different interfaces.)

* The [`--pid-file`](mysqld-safe.html#option_mysqld_safe_pid-file) option is very important if you are using [**mysqld\_safe**](mysqld-safe.html) to start [**mysqld**](mysqld.html) (for example, [`--mysqld=mysqld_safe`](mysqld-safe.html#option_mysqld_safe_mysqld)) Every [**mysqld**](mysqld.html) should have its own process ID file. The advantage of using [**mysqld\_safe**](mysqld-safe.html) instead of [**mysqld**](mysqld.html) is that [**mysqld\_safe**](mysqld-safe.html) monitors its [**mysqld**](mysqld.html) process and restarts it if the process terminates due to a signal sent using `kill -9` or for other reasons, such as a segmentation fault.

* You might want to use the [`--user`](server-options.html#option_mysqld_user) option for [**mysqld**](mysqld.html), but to do this you need to run the [**mysqld\_multi**](mysqld-multi.html) script as the Unix superuser (`root`). Having the option in the option file doesn't matter; you just get a warning if you are not the superuser and the [**mysqld**](mysqld.html) processes are started under your own Unix account.

 The following example shows how you might set up an option file for use with [**mysqld\_multi**](mysqld-multi.html). The order in which the [**mysqld**](mysqld.html) programs are started or stopped depends on the order in which they appear in the option file. Group numbers need not form an unbroken sequence. The first and fifth `[mysqld*`N`*]` groups were intentionally omitted from the example to illustrate that you can have “gaps” in the option file. This gives you more flexibility.

```
# This is an example of a my.cnf file for mysqld_multi.
# Usually this file is located in home dir ~/.my.cnf or /etc/my.cnf

[mysqld_multi]
mysqld     = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user       = multi_admin
password   = my_password

[mysqld2]
socket     = /tmp/mysql.sock2
port       = 3307
pid-file   = /usr/local/mysql/data2/hostname.pid2
datadir    = /usr/local/mysql/data2
language   = /usr/local/mysql/share/mysql/english
user       = unix_user1

[mysqld3]
mysqld     = /path/to/mysqld_safe
ledir      = /path/to/mysqld-binary/
mysqladmin = /path/to/mysqladmin
socket     = /tmp/mysql.sock3
port       = 3308
pid-file   = /usr/local/mysql/data3/hostname.pid3
datadir    = /usr/local/mysql/data3
language   = /usr/local/mysql/share/mysql/swedish
user       = unix_user2

[mysqld4]
socket     = /tmp/mysql.sock4
port       = 3309
pid-file   = /usr/local/mysql/data4/hostname.pid4
datadir    = /usr/local/mysql/data4
language   = /usr/local/mysql/share/mysql/estonia
user       = unix_user3

[mysqld6]
socket     = /tmp/mysql.sock6
port       = 3311
pid-file   = /usr/local/mysql/data6/hostname.pid6
datadir    = /usr/local/mysql/data6
language   = /usr/local/mysql/share/mysql/japanese
user       = unix_user4
```

 See [Section 4.2.2.2, “Using Option Files”](option-files.html).

