4.3 Server and Server-Startup Programs

This section describes *note 'mysqld': mysqld, the MySQL server, and several programs that are used to start the server.

 File: manual.info.tmp, Node: mysqld, Next: mysqld-safe, Prev: programs-server, Up: programs-server

4.3.1 mysqld -- The MySQL Server

*note 'mysqld': mysqld, also known as MySQL Server, is a single multithreaded program that does most of the work in a MySQL installation. It does not spawn additional processes. MySQL Server manages access to the MySQL data directory that contains databases and tables. The data directory is also the default location for other information such as log files and status files.

Note:

Some installation packages contain a debugging version of the server named note 'mysqld-debug': mysqld. Invoke this version instead of note 'mysqld': mysqld. for debugging support, memory allocation checking, and trace file support (see *note making-trace-files::).

When MySQL server starts, it listens for network connections from client programs and manages access to databases on behalf of those clients.

The *note 'mysqld': mysqld. program has many options that can be specified at startup. For a complete list of options, run this command:

 mysqld --verbose --help

MySQL Server also has a set of system variables that affect its operation as it runs. System variables can be set at server startup, and many of them can be changed at runtime to effect dynamic server reconfiguration. MySQL Server also has a set of status variables that provide information about its operation. You can monitor these status variables to access runtime performance characteristics.

For a full description of MySQL Server command options, system variables, and status variables, see note mysqld-server::. For information about installing MySQL and setting up the initial configuration, see note installing::.

 File: manual.info.tmp, Node: mysqld-safe, Next: mysql-server, Prev: mysqld, Up: programs-server

4.3.2 mysqld_safe -- MySQL Server Startup Script

note 'mysqld_safe': mysqld-safe. is the recommended way to start a note 'mysqld': mysqld. server on Unix. *note 'mysqld_safe': mysqld-safe. adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log. A description of error logging is given later in this section.

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, note 'mysqld_safe': mysqld-safe. is not installed because it is unnecessary. For more information, see note using-systemd::.

One implication of the non-use of *note 'mysqld_safe': mysqld-safe. on platforms that use systemd for server management is that use of '[mysqld_safe]' or '[safe_mysqld]' sections in option files is not supported and might lead to unexpected behavior.

note 'mysqld_safe': mysqld-safe. tries to start an executable named note 'mysqld': mysqld. To override the default behavior and specify explicitly the name of the server you want to run, specify a '--mysqld' or '--mysqld-version' option to note 'mysqld_safe': mysqld-safe. You can also use '--ledir' to indicate the directory where note 'mysqld_safe': mysqld-safe. should look for the server.

Many of the options to note 'mysqld_safe': mysqld-safe. are the same as the options to note 'mysqld': mysqld. See *note server-options::.

Options unknown to note 'mysqld_safe': mysqld-safe. are passed to note 'mysqld': mysqld. if they are specified on the command line, but ignored if they are specified in the '[mysqld_safe]' group of an option file. See *note option-files::.

note 'mysqld_safe': mysqld-safe. reads all options from the '[mysqld]', '[server]', and '[mysqld_safe]' sections in option files. For example, if you specify a '[mysqld]' section like this, note 'mysqld_safe': mysqld-safe. finds and uses the '--log-error' option:

 [mysqld]
 log-error=error.log

For backward compatibility, *note 'mysqld_safe': mysqld-safe. also reads '[safe_mysqld]' sections, but to be current you should rename such sections to '[mysqld_safe]'.

note 'mysqld_safe': mysqld-safe. accepts options on the command line and in option files, as described in the following table. For information about option files used by MySQL programs, see note option-files::.

mysqld_safe Options

Option Name Description IntroducedDeprecated

-basedir

Path to MySQL installation directory

-core-file-size

Size of core file that mysqld should be able to create

-datadir

Path to data directory

-defaults-extra-file

Read named option file in addition to usual option files

-defaults-file

Read only named option file

-help

Display help message and exit

-ledir

Path to directory where server is located

-log-error

Write error log to named file

-malloc-lib

Alternative malloc library to use for mysqld

-mysqld

Name of server program to start (in ledir directory)

-mysqld-safe-log-timestamps

Timestamp format 5.7.11 for logging

-mysqld-version

Suffix for server program name

-nice

Use nice program to set server scheduling priority

-no-defaults

Read no option files

-open-files-limit

Number of files that mysqld should be able to open

-pid-file

Path name of server process ID file

-plugin-dir

Directory where plugins are installed

-port

Port number on which to listen for TCP/IP connections

-skip-kill-mysqld

Do not try to kill stray mysqld processes

-skip-syslog

Do not write Yes error messages to
syslog; use error log file

-socket

Socket file on which to listen for Unix socket connections

-syslog

Write error Yes messages to
syslog

-syslog-tag

Tag suffix for Yes messages written
to syslog

-timezone

Set TZ time zone environment variable to named value

-user

Run mysqld as user having name user_name or numeric user ID user_id

If you execute *note 'mysqld_safe': mysqld-safe. with the '--defaults-file' or '--defaults-extra-file' option to name an option file, the option must be the first one given on the command line or the option file is not used. For example, this command does not use the named option file:

 mysql> mysqld_safe --port=PORT_NUM --defaults-file=FILE_NAME

Instead, use the following command:

 mysql> mysqld_safe --defaults-file=FILE_NAME --port=PORT_NUM

The note 'mysqld_safe': mysqld-safe. script is written so that it normally can start a server that was installed from either a source or a binary distribution of MySQL, even though these types of distributions typically install the server in slightly different locations. (See note installation-layouts::.) *note 'mysqld_safe': mysqld-safe. expects one of the following conditions to be true:

Because note 'mysqld_safe': mysqld-safe. tries to find the server and databases relative to its own working directory, you can install a binary distribution of MySQL anywhere, as long as you run note 'mysqld_safe': mysqld-safe. from the MySQL installation directory:

 cd MYSQL_INSTALLATION_DIRECTORY
 bin/mysqld_safe &

If *note 'mysqld_safe': mysqld-safe. fails, even when invoked from the MySQL installation directory, specify the '--ledir' and '--datadir' options to indicate the directories in which the server and databases are located on your system.

note 'mysqld_safe': mysqld-safe. tries to use the 'sleep' and 'date' system utilities to determine how many times per second it has attempted to start. If these utilities are present and the attempted starts per second is greater than 5, note 'mysqld_safe': mysqld-safe. waits 1 full second before starting again. This is intended to prevent excessive CPU usage in the event of repeated failures. (Bug #11761530, Bug #54035)

When you use note 'mysqld_safe': mysqld-safe. to start note 'mysqld': mysqld, note 'mysqld_safe': mysqld-safe. arranges for error (and notice) messages from itself and from note 'mysqld': mysqld. to go to the same destination.

There are several *note 'mysqld_safe': mysqld-safe. options for controlling the destination of these messages:

If none of these options is given, the default is '--skip-syslog'.

When *note 'mysqld_safe': mysqld-safe. writes a message, notices go to the logging destination ('syslog' or the error log file) and 'stdout'. Errors go to the logging destination and 'stderr'.

Note:

Controlling note 'mysqld': mysqld. logging from note 'mysqld_safe': mysqld-safe. is deprecated as of MySQL 5.7.5. Use the server's native 'syslog' support instead. For more information, see *note error-log-syslog::.

 File: manual.info.tmp, Node: mysql-server, Next: mysqld-multi, Prev: mysqld-safe, Up: programs-server

4.3.3 mysql.server -- MySQL Server Startup Script

MySQL distributions on Unix and Unix-like system include a script named note 'mysql.server': mysql-server, which starts the MySQL server using note 'mysqld_safe': mysqld-safe. 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.

note 'mysql.server': mysql-server. is the script name as used within the MySQL source tree. The installed name might be different (for example, note 'mysqld': mysqld. or note 'mysql': mysql.). In the following discussion, adjust the name note 'mysql.server': mysql-server. as appropriate for your system.

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, note 'mysql.server': mysql-server. and note 'mysqld_safe': mysqld-safe. are not installed because they are unnecessary. For more information, see *note using-systemd::.

To start or stop the server manually using the *note 'mysql.server': mysql-server. script, invoke it from the command line with 'start' or 'stop' arguments:

 mysql.server start
 mysql.server stop

note 'mysql.server': mysql-server. changes location to the MySQL installation directory, then invokes note 'mysqld_safe': mysqld-safe. To run the server as some specific user, add an appropriate 'user' option to the '[mysqld]' group of the global '/etc/my.cnf' option file, as shown later in this section. (It is possible that you must edit note 'mysql.server': mysql-server. 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 note 'mysqld_safe': mysqld-safe. If you do this, your modified version of *note 'mysql.server': mysql-server. may be overwritten if you upgrade MySQL in the future; make a copy of your edited version that you can reinstall.)

note 'mysql.server stop': mysql-server. stops the server by sending a signal to it. You can also stop the server manually by executing note 'mysqladmin shutdown': mysqladmin.

To start and stop MySQL automatically on your server, you must add start and stop commands to the appropriate places in your '/etc/rc*' files:

*note 'mysql.server': mysql-server. reads options from the '[mysql.server]' and '[mysqld]' sections of option files. For backward compatibility, it also reads '[mysql_server]' sections, but to be current you should rename such sections to '[mysql.server]'.

You can add options for *note 'mysql.server': mysql-server. in a global '/etc/my.cnf' file. A typical 'my.cnf' file might look like this:

 [mysqld]
 datadir=/usr/local/mysql/var
 socket=/var/tmp/mysql.sock
 port=3306
 user=mysql

 [mysql.server]
 basedir=/usr/local/mysql

The note 'mysql.server': mysql-server. script supports the options shown in the following table. If specified, they must be placed in an option file, not on the command line. note 'mysql.server': mysql-server. supports only 'start' and 'stop' as command-line arguments.

mysql.server Option-File Options

Option Name Description Type

'basedir'

Path to Directory name MySQL
installation directory

'datadir'

Path to Directory name MySQL data
directory

'pid-file'

File in File name which server
should write its process ID

'service-startup-timeout'

How long to Integer wait for server startup

 File: manual.info.tmp, Node: mysqld-multi, Prev: mysql-server, Up: programs-server

4.3.4 mysqld_multi -- Manage Multiple MySQL Servers

note 'mysqld_multi': mysqld-multi. is designed to manage several note 'mysqld': mysqld. 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, note 'mysqld_multi': mysqld-multi. is not installed because it is unnecessary. For information about using systemd to handle multiple MySQL instances, see note using-systemd::.

note 'mysqld_multi': mysqld-multi. searches for groups named '[mysqldN]' in 'my.cnf' (or in the file named by the '--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 note 'mysqld_multi': mysqld-multi. 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 note 'mysqld': mysqld. (See, for example, note automatic-start::.) 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 *note multiple-servers::.

To invoke *note 'mysqld_multi': mysqld-multi, 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, *note 'mysqld_multi': mysqld-multi. 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

*note 'mysqld_multi': mysqld-multi. searches for option files as follows:

For additional information about these and other option-file options, see *note option-file-options::.

Option files read are searched for '[mysqld_multi]' and '[mysqldN]' option groups. The '[mysqld_multi]' group can be used for options to note 'mysqld_multi': mysqld-multi. itself. '[mysqldN]' groups can be used for options passed to specific note 'mysqld': mysqld. instances.

The '[mysqld]' or '[mysqld_safe]' groups can be used for common options read by all instances of note 'mysqld': mysqld. or note 'mysqld_safe': mysqld-safe. You can specify a '--defaults-file=FILE_NAME' 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.

*note 'mysqld_multi': mysqld-multi. supports the following options.

Some notes about *note 'mysqld_multi': mysqld-multi.:

The following example shows how you might set up an option file for use with note 'mysqld_multi': mysqld-multi. The order in which the note 'mysqld': 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 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 *note option-files::.

 File: manual.info.tmp, Node: programs-installation, Next: programs-client, Prev: programs-server, Up: programs