mysqld_safe is the recommended way to start a mysqld server on Unix. mysqld_safe是在Unix上启动mysqld服务器的推荐方法。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.mysqld_safe添加了一些安全功能,例如在发生错误时重新启动服务器,并将运行时信息记录到错误日志中。本节稍后将介绍错误日志记录。
For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. 对于某些Linux平台,RPM或Debian软件包中的MySQL安装包括用于管理MySQL服务器启动和关闭的systemd支持。On these platforms, mysqld_safe is not installed because it is unnecessary. 在这些平台上,没有安装mysqld_safe,因为它是不必要的。For more information, see Section 2.5.9, “Managing MySQL Server with systemd”.有关更多信息,请参阅第2.5.9节,“使用systemd管理MySQL服务器”。
mysqld_safe tries to start an executable named mysqld. mysqld_safe尝试启动一个名为mysqld的可执行文件。To override the default behavior and specify explicitly the name of the server you want to run, specify a 要覆盖默认行为并明确指定要运行的服务器的名称,请在mysqld_safe中指定--mysqld
or --mysqld-version
option to mysqld_safe. --mysqld
或--mysqld-version
选项。You can also use 您还可以使用--ledir
to indicate the directory where mysqld_safe should look for the server.--ledir
来指示mysqld_safe应该查找服务器的目录。
Many of the options to mysqld_safe are the same as the options to mysqld. mysqld_safe的许多选项与mysqld的选项相同。See Section 5.1.7, “Server Command Options”.请参阅第5.1.7节,“服务器命令选项”。
Options unknown to mysqld_safe are passed to mysqld if they are specified on the command line, but ignored if they are specified in the 如果在命令行上指定了mysqld_safe未知的选项,则将其传递给mysqld,但如果在选项文件的[mysqld_safe]
group of an option file. [mysqld_safe]
组中指定了这些选项,则忽略这些选项。See Section 4.2.2.2, “Using Option Files”.请参阅第4.2.2.2节,“使用选项文件”。
mysqld_safe reads all options from the mysqld_safe从选项文件中的[mysqld]
, [server]
, and [mysqld_safe]
sections in option files. [mysqld]
、[server]
和[mysqldsafe]
部分读取所有选项。For example, if you specify a 例如,如果您指定这样的[mysqld]
section like this, mysqld_safe finds and uses the --log-error
option:[mysqld]
部分,mysqld_safe会查找并使用--log-error
选项:
[mysqld] log-error=error.log
For backward compatibility, mysqld_safe also reads 为了向后兼容,mysqld_safe还读取[safe_mysqld]
sections, but to be current you should rename such sections to [mysqld_safe]
.[safe_mysqld]
节,但要成为最新版本,您应该将这些节重命名为[mysqld_safe]
。
mysqld_safe accepts options on the command line and in option files, as described in the following table. mysqld_safe接受命令行和选项文件中的选项,如下表所述。For information about option files used by MySQL programs, see Section 4.2.2.2, “Using Option Files”.有关MySQL程序使用的选项文件的信息,请参阅第4.2.2.2节,“使用选项文件”。
Table 4.6 mysqld_safe Options
--basedir | |
--core-file-size | |
--datadir | |
--defaults-extra-file | |
--defaults-file | |
--help | |
--ledir | |
--log-error | |
--malloc-lib | |
--mysqld | |
--mysqld-safe-log-timestamps | |
--mysqld-version | |
--nice | |
--no-defaults | |
--open-files-limit | |
--pid-file | |
--plugin-dir | |
--port | |
--skip-kill-mysqld | |
--skip-syslog | |
--socket | |
--syslog | |
--syslog-tag | |
--timezone | |
--user |
Display a help message and exit.显示帮助消息并退出。
The path to the MySQL installation directory.MySQL安装目录的路径。
The size of the core file that mysqld should be able to create. The option value is passed to ulimit -c.mysqld应该能够创建的核心文件的大小。选项值传递给ulimit -c
。
The innodb_buffer_pool_in_core_file
variable can be used to reduce the size of core files on operating systems that support it. innodb_buffer_pool_in_core_file
变量可用于减小支持它的操作系统上的核心文件的大小。For more information, see Section 15.8.3.7, “Excluding Buffer Pool Pages from Core Files”.有关更多信息,请参阅第15.8.3.7节,“从核心文件中排除缓冲池页面”。
The path to the data directory.数据目录的路径。
--defaults-extra-file=
file_name
Read this option file in addition to the usual option files. If the file does not exist or is otherwise inaccessible, the server exits with an error. 除了通常的选项文件外,还要读取此选项文件。如果文件不存在或无法访问,服务器将退出并显示错误。If 如果file_name
is not an absolute path name, it is interpreted relative to the current directory. This must be the first option on the command line if it is used.file_name
不是绝对路径名,则会相对于当前目录进行解释。如果使用,这必须是命令行上的第一个选项。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
Use only the given option file. 仅使用给定的选项文件。If the file does not exist or is otherwise inaccessible, the server exits with an error. 如果文件不存在或无法访问,服务器将退出并显示错误。If 如果file_name
is not an absolute path name, it is interpreted relative to the current directory. This must be the first option on the command line if it is used.file_name
不是绝对路径名,则会相对于当前目录进行解释。如果使用,这必须是命令行上的第一个选项。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
If mysqld_safe cannot find the server, use this option to indicate the path name to the directory where the server is located.如果mysqld_safe找不到服务器,请使用此选项指示服务器所在目录的路径名。
This option is accepted only on the command line, not in option files. 此选项仅在命令行上接受,不在选项文件中接受。On platforms that use systemd, the value can be specified in the value of 在使用systemd的平台上,可以在MYSQLD_OPTS
. MYSQLD_OPTS
的值中指定该值。See Section 2.5.9, “Managing MySQL Server with systemd”.请参阅第2.5.9节,“使用systemd管理MySQL服务器”。
Write the error log to the given file. 将错误日志写入给定文件。See Section 5.4.2, “The Error Log”.请参阅第5.4.2节,“错误日志”。
This option controls the format for timestamps in log output produced by mysqld_safe. 此选项控制mysqld_safe生成的日志输出中时间戳的格式。The following list describes the permitted values. 以下列表描述了允许的值。For any other value, mysqld_safe logs a warning and uses 对于任何其他值,mysqld_safe都会记录警告并使用UTC
format.UTC
格式。
UTC
, utc
ISO 8601 UTC format (same as ISO 8601 UTC格式(与服务器的--log_timestamps=UTC
for the server). This is the default.--log_timestamps=UTC
相同)。这是默认设置。
SYSTEM
, system
ISO 8601 local time format (same as ISO 8601本地时间格式(与服务器的--log_timestamps=SYSTEM
for the server).--log_timestamps=SYSTEM
相同)。
HYPHEN
, hyphen
YY-MM-DD h:mm:ss
format, as in mysqld_safe for MySQL 5.6.YY-MM-DD h:MM:ss
格式,如MySQL 5.6的mysqld_safe。
LEGACY
, legacy
YYMMDD hh:mm:ss
format, as in mysqld_safe prior to MySQL 5.6.
The name of the library to use for memory allocation instead of the system 用于内存分配的库的名称,而不是系统malloc()
library. malloc()
库。The option value must be one of the directories 选项值必须是/usr/lib
, /usr/lib64
, /usr/lib/i386-linux-gnu
, or /usr/lib/x86_64-linux-gnu
./usr/lib
、/usr/lib64
、/usr/lib/i386-linux-gnu
或/usr/lib/x86_64-linux-gnu
目录之一。
The --malloc-lib
option works by modifying the LD_PRELOAD
environment value to affect dynamic linking to enable the loader to find the memory-allocation library when mysqld runs:--malloc-lib
选项通过修改LD_PRELOAD
环境值来影响动态链接,使加载器在mysqld运行时能够找到内存分配库:
If the option is not given, or is given without a value (如果没有给出选项,或者没有给出值(--malloc-lib=
), LD_PRELOAD
is not modified and no attempt is made to use tcmalloc
.--malloc-lib=
),则不会修改LD_PRELOAD
,也不会尝试使用tcmalloc
。
Prior to MySQL 8.0.21, if the option is given as 在MySQL 8.0.21之前,如果选项为--malloc-lib=tcmalloc
, mysqld_safe looks for a tcmalloc
library in /usr/lib
. --malloc-lib=tcmalloc
,mysqld_safe会在/usr/lib
中查找tcmalloc
库。If 如果找到tmalloc
is found, its path name is added to the beginning of the LD_PRELOAD
value for mysqld. tmalloc
,则将其路径名添加到mysqld的LD_PRELOAD
值的开头。If 如果未找到tcmalloc
is not found, mysqld_safe aborts with an error.tcmalloc
,mysqld_safe将中止并返回错误。
As of MySQL 8.0.21, 从MySQL 8.0.21开始,tcmalloc
is not a permitted value for the --malloc-lib
option.tcmalloc
不是--malloc-lib
选项的允许值。
If the option is given as 如果选项为--malloc-lib=
, that full path is added to the beginning of the /path/to/some/library
LD_PRELOAD
value. --malloc-lib=/path/to/some/lib
,则完整路径将添加到LD_PRELOAD值的开头。If the full path points to a nonexistent or unreadable file, mysqld_safe aborts with an error.如果完整路径指向不存在或不可读的文件,mysqld_safe将中止并返回错误。
For cases where mysqld_safe adds a path name to 对于mysqld_safe向LD_PRELOAD
, it adds the path to the beginning of any existing value the variable already has.LD_PRELOAD
添加路径名的情况,它会将路径添加到变量已经具有的任何现有值的开头。
On systems that manage the server using systemd, mysqld_safe is not available. 在使用systemd管理服务器的系统上,mysqld_safe不可用。Instead, specify the allocation library by setting 相反,通过在LD_PRELOAD
in /etc/sysconfig/mysql
./etc/sysconfig/mysql
中设置LD_PRELOAD
来指定分配库。
Linux users can use the Linux用户可以在/usr/lib中安装libtcmalloc_minimal.so
library on any platform for which a tcmalloc
package is installed in /usr/lib
by adding these lines to the my.cnf
file:tcmalloc
包的任何平台上使用libtcmalloc_minimal.so
库,方法是在my.cnf
文件中添加以下行:
[mysqld_safe] malloc-lib=tcmalloc
To use a specific 要使用特定的tcmalloc
library, specify its full path name. Example:tcmalloc
库,请指定其完整路径名。例子:
[mysqld_safe] malloc-lib=/opt/lib/libtcmalloc_minimal.so
The name of the server program (in the 要启动的服务器程序的名称(在ledir
directory) that you want to start. ledir
目录中)。This option is needed if you use the MySQL binary distribution but have the data directory outside of the binary distribution. 如果您使用MySQL二进制发行版,但数据目录在二进制发行版之外,则需要此选项。If mysqld_safe cannot find the server, use the 如果mysqld_safe找不到服务器,请使用--ledir
option to indicate the path name to the directory where the server is located.--ledir
选项指示服务器所在目录的路径名。
This option is accepted only on the command line, not in option files. 此选项仅在命令行上接受,不在选项文件中接受。On platforms that use systemd, the value can be specified in the value of 在使用systemd的平台上,可以在MYSQLD_OPTS
. See Section 2.5.9, “Managing MySQL Server with systemd”.MYSQLD_OPTS
的值中指定该值。请参阅第2.5.9节,“使用systemd管理MySQL服务器”。
This option is similar to the 此选项类似于--mysqld
option, but you specify only the suffix for the server program name. --mysqld
选项,但只指定服务器程序名的后缀。The base name is assumed to be mysqld. 基本名称假定为mysqld。For example, if you use 例如,如果使用--mysqld-version=debug
, mysqld_safe starts the mysqld-debug program in the ledir
directory. --mysqld version=debug
,mysqld_safe将启动ledir
目录中的mysqld调试程序。If the argument to 如果--mysqld-version
is empty, mysqld_safe uses mysqld in the ledir
directory.--mysqld-version
的参数为空,mysqld_safe将使用ledir
目录中的mysqld。
This option is accepted only on the command line, not in option files. 此选项仅在命令行上接受,不在选项文件中接受。On platforms that use systemd, the value can be specified in the value of 在使用systemd的平台上,可以在MYSQLD_OPTS
. MYSQLD_OPTS
的值中指定该值。See Section 2.5.9, “Managing MySQL Server with systemd”.请参阅第2.5.9节,“使用systemd管理MySQL服务器”。
Use the 使用nice
program to set the server's scheduling priority to the given value.nice
程序将服务器的调度优先级设置为给定值。
Do not read any option files. If program startup fails due to reading unknown options from an option file, 不要读取任何选项文件。如果程序启动因从选项文件中读取未知选项而失败,则可以使用--no-defaults
can be used to prevent them from being read. This must be the first option on the command line if it is used.--no-defaults
来阻止读取它们。如果使用,这必须是命令行上的第一个选项。
For additional information about this and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关此选项和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”。
The number of files that mysqld should be able to open. The option value is passed to ulimit -n.mysqld应该能够打开的文件数。选项值传递给ulimit -n。
You must start mysqld_safe as 您必须以root
for this to function properly.root
身份启动mysqld_safe才能正常运行。
The path name that mysqld should use for its process ID file.mysqld应用于其进程ID文件的路径名。
The path name of the plugin directory.插件目录的路径名。
The port number that the server should use when listening for TCP/IP connections. The port number must be 1024 or higher unless the server is started by the 服务器在侦听TCP/IP连接时应使用的端口号。除非服务器是由root
operating system user.root
操作系统用户启动的,否则端口号必须为1024或更高。
Do not try to kill stray mysqld processes at startup. This option works only on Linux.不要在启动时试图杀死流浪的mysqld进程。此选项仅适用于Linux。
The Unix socket file that the server should use when listening for local connections.服务器在监听本地连接时应使用的Unix套接字文件。
--syslog
causes error messages to be sent to syslog
on systems that support the logger program. --syslog
会在支持logger程序的系统上向syslog
发送错误消息。--skip-syslog
suppresses the use of syslog
; messages are written to an error log file.--skip-syslog
禁止使用syslog
;消息被写入错误日志文件。
When 当syslog
is used for error logging, the daemon.err
facility/severity is used for all log messages.syslog
用于错误日志记录时,daemon.err
设施/严重性用于所有日志消息。
Using these options to control mysqld logging is deprecated. 不推荐使用这些选项来控制mysqld日志记录。To write error log output to the system log, use the instructions at Section 5.4.2.8, “Error Logging to the System Log”. 要将错误日志输出写入系统日志,请使用第5.4.2.8节,“将错误日志记录到系统日志”中的说明。To control the facility, use the server 要控制该设施,请使用服务器log_syslog_facility
system variable.log_syslog_facility
系统变量。
For logging to 为了将日志记录到syslog
, messages from mysqld_safe and mysqld are written with identifiers of mysqld_safe
and mysqld
, respectively. syslog
,来自mysqld_safe和mysqld的消息分别用mysqld_safe
和mysqld
标识符编写。To specify a suffix for the identifiers, use 要为标识符指定后缀,请使用--syslog-tag=
, which modifies the identifiers to be tag
mysqld_safe-
and tag
mysqld-
.tag
--syslog tag=tag
,它将标识符修改为mysqld_safe-tag
和mysqld-tag
。
Using this option to control mysqld logging is deprecated. 不推荐使用此选项来控制mysqld日志记录。Use the server 请改用服务器log_syslog_tag
system variable instead. log_syslog_tag
系统变量。See Section 5.4.2.8, “Error Logging to the System Log”.请参阅第5.4.2.8节,“系统日志中的错误记录”。
Set the 将TZ
time zone environment variable to the given option value. Consult your operating system documentation for legal time zone specification formats.TZ
时区环境变量设置为给定的选项值。有关法定时区规范格式,请参阅操作系统文档。
Run the mysqld server as the user having the name 以用户名user_name
or the numeric user ID user_id
. (“User” in this context refers to a system login account, not a MySQL user listed in the grant tables.)user_name
或数字用户ID user_id
的用户身份运行mysqld服务器。(在这种情况下,“用户”是指系统登录帐户,而不是授权表中列出的MySQL用户。)
If you execute 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. --defaults-file
或--defaults-extra-file
选项执行mysqld_safe来命名选项文件,则该选项必须是命令行上给出的第一个选项,否则不使用该选项文件。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 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.mysqld_safe脚本的编写方式是,它通常可以启动从MySQL的源代码或二进制发行版安装的服务器,即使这些类型的发行版通常将服务器安装在略有不同的位置。 (See Section 2.1.5, “Installation Layouts”.) (参阅第2.1.5节,“安装布局”。)mysqld_safe expects one of the following conditions to be true:mysqld_safe期望以下条件之一为真:
The server and databases can be found relative to the working directory (the directory from which mysqld_safe is invoked). 服务器和数据库可以相对于工作目录(调用mysqld_safe的目录)找到。For binary distributions, mysqld_safe looks under its working directory for 对于二进制发行版,mysqld_safe在其工作目录下查找bin
and data
directories. bin
和数据目录。For source distributions, it looks for 对于源代码发行版,它会查找libexec
and var
directories. libexec
和var
目录。This condition should be met if you execute mysqld_safe from your MySQL installation directory (for example, 如果从MySQL安装目录(例如,二进制发行版的/usr/local/mysql
for a binary distribution)./usr/local/mysql
)执行mysqld_safe,则应满足此条件。
If the server and databases cannot be found relative to the working directory, mysqld_safe attempts to locate them by absolute path names. 如果找不到相对于工作目录的服务器和数据库,mysqld_safe会尝试通过绝对路径名定位它们。Typical locations are 典型的位置是/usr/local/libexec
and /usr/local/var
. /usr/local/libexec
和/usr/local/var
。The actual locations are determined from the values configured into the distribution at the time it was built. 实际位置是根据构建时配置到分布中的值确定的。They should be correct if MySQL is installed in the location specified at configuration time.如果MySQL安装在配置时指定的位置,则它们应该是正确的。
Because 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 mysqld_safe from the MySQL installation directory:因为mysqld_safe试图找到与其自己的工作目录相关的服务器和数据库,所以你可以在任何地方安装MySQL的二进制发行版,只要你从MySQL安装目录运行mysqld_safe:
cd mysql_installation_directory
bin/mysqld_safe &
If mysqld_safe fails, even when invoked from the MySQL installation directory, specify the 如果mysqld_safe失败,即使从MySQL安装目录调用,也要指定--ledir
and --datadir
options to indicate the directories in which the server and databases are located on your system.--ledir
和--datadir
选项,以指示服务器和数据库位于系统上的目录。
mysqld_safe tries to use the sleep and date system utilities to determine how many times per second it has attempted to start. mysqld_safe试图使用sleep和date系统实用程序来确定它每秒尝试启动的次数。If these utilities are present and the attempted starts per second is greater than 5, mysqld_safe waits 1 full second before starting again. 如果这些实用程序存在,并且每秒尝试的启动次数大于5次,mysqld_safe将等待整整1秒后再重新启动。This is intended to prevent excessive CPU usage in the event of repeated failures. (Bug #11761530, Bug #54035)这是为了防止在重复故障的情况下过度使用CPU。(错误号11761530,错误号54035)
When you use mysqld_safe to start mysqld, mysqld_safe arranges for error (and notice) messages from itself and from mysqld to go to the same destination.当您使用mysqld_safe启动mysqld时,mysqld_safe会将来自自身和mysqld的错误(和通知)消息安排到同一个目标。
There are several mysqld_safe options for controlling the destination of these messages:有几个mysqld_safe选项可以控制这些消息的目标:
--log-error=
file_name
: Write error messages to the named error file.:将错误消息写入指定的错误文件。
--syslog
: Write error messages to :在支持syslog
on systems that support the logger program.logger
程序的系统上向syslog
写入错误消息。
--skip-syslog
: Do not write error messages to :不要将错误消息写入syslog
. syslog
。Messages are written to the default error log file (消息将写入默认错误日志文件(数据目录中的
in the data directory), or to a named file if the host_name
.err--log-error
option is given.host_name.err
),或者如果给出了--log-error
选项,则写入一个命名文件。
If none of these options is given, the default is 如果没有给出这些选项,则默认为--skip-syslog
.--skip-syslog
。
When mysqld_safe writes a message, notices go to the logging destination (当mysqld_safe写入消息时,通知会发送到日志记录目标(syslog
or the error log file) and stdout
. syslog
或错误日志文件)和stdout
。Errors go to the logging destination and 错误将转到日志记录目标和stderr
.stderr
。
Controlling mysqld logging from mysqld_safe is deprecated. Use the server's native 不推荐从mysqld_safe控制mysqld日志记录。请改用服务器的本机syslog
support instead. syslog
支持。For more information, see Section 5.4.2.8, “Error Logging to the System Log”.有关更多信息,请参阅第5.4.2.8节,“系统日志错误记录”。