mysqld_multi

MariaDB starting with 10.4.6

From MariaDB 10.4.6, mariadbd-multi is a symlink to mysqld_multi.

MariaDB starting with 10.5.2

From MariaDB 10.5.2, mariadbd-multi is the name of the server, with mysqld_multi a symlink .

Before using mysqld_multi be sure that you understand the meanings of the options that are passed to the mysqld servers and why you would want to have separate mysqld processes. Beware of the dangers of using multiple mysqld 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.

The mysqld_multi startup script is in MariaDB distributions on Linux and Unix. It is a wrapper that is designed to manage several mysqld processes running on the same host. In order for multiple mysqld processes to work on the same host, these processes must:

  • Use different Unix socket files for local connections.
  • Use different TCP/IP ports for network connections.
  • Use different data directories.
  • Use different process ID files (specified by the --pid-file option) if using mysqld_safe to start mysqld.

mysqld_multi can start or stop servers, or report their current status.

Using mysqld_multi

The command to use mysqld_multi and the general syntax is:

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

start, stop, and report indicate which operation to perform.

You can specify which servers to perform the operation on by providing one or more GNR values. GNR refers to an option group number, and it is explained more in the option groups section below. If there is no GNR list, then mysqld_multi performs the operation for all GNR values found in its option files.

Multiple GNR values can be specified as a comma-separated list. GNR values can also be specified as a range by separating the numbers by a dash. There must not be any whitespace characters in the GNR list.

For example:

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

Options

mysqld_multi supports the following options:

Option Description
--example Give an example of a config file with extra information.
--help Display help and exit.
--log=filename Specify the path and name of the log file. If the file exists, log output is appended to it.
--mysqladmin=prog_name The mysqladmin binary to be used to stop servers. Can be given within groups [mysqld#].
--mysqld=prog_name The mysqld binary to be used. Note that you can also specify mysqld_safe as the value for this option. If you use mysqld_safe to start the server, you can include the mysqld or ledir options in the corresponding [mysqldN] option group. These options indicate the name of the server that mysqld_safe should start and the path name of the directory where the server is located. Example:
[mysqld38]
mysqld = mysqld-debug
ledir = /opt/local/mysql/libexec.
--no-log Print to stdout instead of the log file. By default the log file is turned on.
--password=password The password of the MariaDB account to use when invoking mysqladmin. Note that the password value is not optional for this option, unlike for other MariaDB programs.
--silent Silent mode; disable warnings.
--tcp-ip Connect to the MariaDB server(s) via the TCP/IP port instead of the UNIX socket. This affects stopping and reporting. If a socket file is missing, the server may still be running, but can be accessed only via the TCP/IP port. By default connecting is done via the UNIX socket. This option affects stop and report operations.
--user=username The user name of the MariaDB account to use when invoking mysqladmin.
--verbose Be more verbose.
--version Display version information and exit.
--wsrep-new-cluster Bootstrap a cluster. Added in MariaDB 10.1.15.

Option Files

In addition to reading options from the command-line, mysqld_multi can also read options from option files. If an unknown option is provided to mysqld_multi in an option file, then it is ignored.

The following options relate to how MariaDB command-line tools handles option files. They must be given as the first argument on the command-line:

Option Description
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# In addition to the default option groups, also read option groups with this suffix.

Option Groups

mysqld_safe reads options from the following option groups from option files:

Group Description
[mysqld_multi] Options read by mysqld_multi, which includes both MariaDB Server and MySQL Server.

mysqld_multi also searches option files for option groups with names like [mysqldN], where N can be any positive integer. This number is referred to in the following discussion as the option group number, or GNR:

Group Description
[mysqldN] Options read by a mysqld instance managed by mysqld_multi, which includes both MariaDB Server and MySQL Server. The N refers to the instance's GNR.

GNR values distinguish option groups from one another and are used as arguments to mysqld_multi to specify which servers you want to start, stop, or obtain a status report for. The GNR value should be the number at the end of the option group name in the option file. For example, the GNR for an option group named [mysqld17] is 17.

Options listed in these option groups are the same that you would use in the regular server option groups used for configuring mysqld. 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.

The [mysqld_multi] option group can be used for options that are needed for mysqld_multi itself. [mysqldN] option groups can be used for options passed to specific mysqld instances.

The regular server option groups can also be used for common options that are read by all instances:

Group Description
[mysqld] Options read by mysqld, which includes both MariaDB Server and MySQL Server.
[server] Options read by MariaDB Server.
[mysqld-X.Y] Options read by a specific version of mysqld, which includes both MariaDB Server and MySQL Server. For example, [mysqld-5.5].
[mariadb] Options read by MariaDB Server.
[mariadb-X.Y] Options read by a specific version of MariaDB Server.
[client-server] Options read by all MariaDB client programs and the MariaDB Server. This is useful for options like socket and port, which is common between the server and the clients.
[galera] Options read by a galera-capable MariaDB Server. Available on systems compiled with Galera support.

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

mysqld_multi --example

Authentication and Privileges

Make sure that the MariaDB account used for stopping the mysqld processes (with the mysqladmin utility) has the same user name and password for each server. Also, make sure that the account has the 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:

shell> mysql -u root -S /tmp/mysql.sock -p
Enter password:
mysql> GRANT SHUTDOWN ON *.*
 -> TO ´multi_admin´@´localhost´ IDENTIFIED BY ´multipass´;

Change the connection parameters appropriately when connecting to each one. Note that the host name part of the account name must allow you to connect as multi_admin from the host where you want to run mysqld_multi.

User Account

Make sure that the data directory for each server is fully accessible to the Unix account that the specific mysqld process is started as. If you run the mysqld_multi script as the Unix root account, and if you want the mysqld process to be started with another Unix account, then you can use use the --user option with mysqld. If you specify the --user option in an option file, and if you did not run the mysqld_multi script as the Unix root account, then it will just log a warning and the mysqld processes are started under the original Unix account.

Do not run the mysqld process as the Unix root account, unless you know what you are doing.

Example

The following example shows how you might set up an option file for use with mysqld_multi. The order in which the mysqld 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 [mysqldN] groups were intentionally omitted from the example to illustrate that you can have “gaps” in the option file. This gives you more flexibility.

           # This file should probably be in your home dir (~/.my.cnf)
           # or /etc/my.cnf
           # Version 2.1 by Jani Tolonen
           [mysqld_multi]
           mysqld     = /usr/local/bin/mysqld_safe
           mysqladmin = /usr/local/bin/mysqladmin
           user       = multi_admin
           password   = multipass
           [mysqld2]
           socket     = /tmp/mysql.sock2
           port       = 3307
           pid-file   = /usr/local/mysql/var2/hostname.pid2
           datadir    = /usr/local/mysql/var2
           language   = /usr/local/share/mysql/english
           user       = john
           [mysqld3]
           socket     = /tmp/mysql.sock3
           port       = 3308
           pid-file   = /usr/local/mysql/var3/hostname.pid3
           datadir    = /usr/local/mysql/var3
           language   = /usr/local/share/mysql/swedish
           user       = monty
           [mysqld4]
           socket     = /tmp/mysql.sock4
           port       = 3309
           pid-file   = /usr/local/mysql/var4/hostname.pid4
           datadir    = /usr/local/mysql/var4
           language   = /usr/local/share/mysql/estonia
           user       = tonu
           [mysqld6]
           socket     = /tmp/mysql.sock6
           port       = 3311
           pid-file   = /usr/local/mysql/var6/hostname.pid6
           datadir    = /usr/local/mysql/var6
           language   = /usr/local/share/mysql/japanese
           user       = jani
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.

© 2021 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/mysqld_multi/