8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 6 个 MySQL 程序 / 6.3 服务器和服务器启动程序 / 6.3.2 mysqld_safe — MySQL 服务器启动脚本
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 92%

6.3.2 mysqld_safe — MySQL 服务器启动脚本6.3.2 mysqld_safe — MySQL Server Startup Script

mysqld_safe 是在 Unix 上启动 mysqld 服务器的推荐方式。mysqld_safe 增加了一些安全功能,例如在发生错误时重启服务器,以及将运行时信息记录到错误日志中。本节后面将给出错误日志记录的介绍。mysqld_safe is the recommended way to start a mysqld server on Unix. 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

对于某些 Linux 平台,通过 RPM 或 Debian 软件包安装 MySQL 时,包括了用于管理 MySQL 服务器启动和关闭的 systemd 支持。在这些平台上,mysqld_safe 不会被安装,因为它是不必要的。更多信息请参见 第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。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_safe is not installed because it is unnecessary. For more information, see Section 2.5.9, “Managing MySQL Server with systemd”.

One implication of the non-use of mysqld_safe on platforms that use systemd for server management is that use of [mysqld_safe]或者[safe_mysqld] sections in option files is not supported and might lead to unexpected behavior.One implication of the non-use of 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.

mysqld_safe 尝试启动一个名为 mysqld 的可执行文件。要覆盖默认行为并明确指定要运行的服务器名称,请为 mysqld_safe 指定 --mysqld 或 --mysqld-version 选项。你也可以使用 --ledir 指定 mysqld_safe 应该查找服务器的目录。mysqld_safe tries to start an executable named 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 mysqld_safe. You can also use --ledir to indicate the directory where mysqld_safe should look for the server.

许多用于 mysqld_safe 的选项与用于 mysqld 的选项相同。请参见 第 7.1.7 节,“服务器命令选项”。Many of the options to mysqld_safe are the same as the options to mysqld. See Section 7.1.7, “Server Command Options”.

如果在命令行中指定,mysqld_safe 不认识的选项会传递给 mysqld,但如果在选项文件的 [mysqld_safe] 组中指定,则会被忽略。参见 第 6.2.2.2 节,“使用选项文件”。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] group of an option file. See Section 6.2.2.2, “Using Option Files”.

mysqld_safe 从选项文件中的 [mysqld]、[server] 和 [mysqld_safe] 部分读取所有选项。例如,如果你指定了如下的 [mysqld] 部分,mysqld_safe 会找到并使用 --log-error 选项: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, mysqld_safe finds and uses the --log-error option:

[mysqld]
log-error=error.log

为了向后兼容,mysqld_safe 也会读取 [safe_mysqld] 部分,但为了保持最新,您应将这些部分重命名为 [mysqld_safe]。For backward compatibility, mysqld_safe also reads [safe_mysqld] sections, but to be current you should rename such sections to [mysqld_safe].

mysqld_safe 接受命令行和选项文件中的选项,如下表所示。有关 MySQL 程序使用的选项文件的信息,请参见 第 6.2.2.2 节,“使用选项文件”。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 Section 6.2.2.2, “Using Option Files”.

表 6.7 mysqld_safe 选项Table 6.7 mysqld_safe Options

选项名称Option Name 说明Description
--基础目录--basedir MySQL 安装目录的路径Path to MySQL installation directory
--核心文件大小--core-file-size mysqld 应能创建的核心文件大小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 内存分配库--malloc-lib 用于 mysqld 的替代 malloc 库Alternative malloc library to use for mysqld
--mysqld 要启动的服务器程序名称(在 ledir 目录中)Name of server program to start (in ledir directory)
--mysqld-安全日志时间戳--mysqld-safe-log-timestamps 用于日志记录的时间戳格式Timestamp format for logging
--mysqld-版本--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 mysqld 应能够打开的文件数量Number of files that mysqld should be able to open
--pid-文件--pid-file 服务器进程 ID 文件的路径名称Path name of server process ID file
--插件目录--plugin-dir 插件安装的目录Directory where plugins are installed
--端口--port 监听 TCP/IP 连接的端口号Port number on which to listen for TCP/IP connections
--跳过终止 mysqld--skip-kill-mysqld 不要尝试杀死流浪的 mysqld 进程Do not try to kill stray mysqld processes
--跳过系统日志--skip-syslog 不要将错误信息写入系统日志;请使用错误日志文件Do not write error messages to syslog; use error log file
--socket 用于监听 Unix 套接字连接的套接字文件Socket file on which to listen for Unix socket connections
--系统日志--syslog 将错误消息写入系统日志Write error messages to syslog
--系统日志标签--syslog-tag 写入 syslog 消息的标签后缀Tag suffix for messages written to syslog
--时区--timezone 将 TZ 时区环境变量设置为指定值Set TZ time zone environment variable to named value
--用户--user 以用户名为 user_name 或数值用户 ID user_id 的用户身份运行 mysqldRun mysqld as user having name user_name or numeric user ID user_id

  • --help --help

    命令行格式Command-Line Format --help--help

    显示帮助信息并退出。Display a help message and exit.

  • --basedir=dir_name --basedir=dir_name

    命令行格式Command-Line Format --basedir=dir_name--basedir=dir_name
    类型Type 目录名称Directory name

    MySQL 安装目录的路径。The path to the MySQL installation directory.

  • --core-file-size=size --core-file-size=size

    命令行格式Command-Line Format --core-file-size=size--core-file-size=size
    类型Type 字符串String

    mysqld 应能够创建的核心文件的大小。该选项值会传递给 ulimit -c。The size of the core file that mysqld should be able to create. The option value is passed to ulimit -c.

    Note

    innodb_buffer_pool_in_core_file 变量可用于在支持的操作系统上减少核心文件的大小。更多信息,请参阅 第 17.8.3.7 节,“从核心文件中排除或包含缓冲池页”。The innodb_buffer_pool_in_core_file variable can be used to reduce the size of core files on operating systems that support it. For more information, see Section 17.8.3.7, “Excluding or Including Buffer Pool Pages from Core Files”.

  • --datadir=dir_name --datadir=dir_name

    命令行格式Command-Line Format --datadir=dir_name--datadir=dir_name
    类型Type 目录名称Directory name

    数据目录的路径。The path to the data directory.

  • --defaults-extra-file=file_name --defaults-extra-file=file_name

    命令行格式Command-Line Format --defaults-extra-file=file_name--defaults-extra-file=file_name
    类型Type 文件名File name

    除了通常的选项文件之外,还会读取此选项文件。如果文件不存在或无法访问,服务器将以错误退出。如果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.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --defaults-file=file_name --defaults-file=file_name

    命令行格式Command-Line Format --defaults-file=file_name--defaults-file=file_name
    类型Type 文件名File name

    仅使用给定的选项文件。如果文件不存在或无法访问,服务器将以错误退出。如果file_name不是绝对路径名,则将其解释为相对于当前目录。如果使用该选项,它必须是命令行上的第一个选项。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.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --ledir=dir_name --ledir=dir_name

    命令行格式Command-Line Format --ledir=dir_name--ledir=dir_name
    类型Type 目录名称Directory name

    如果mysqld_safe 找不到服务器,请使用此选项指定服务器所在目录的路径名。If mysqld_safe cannot find the server, use this option to indicate the path name to the directory where the server is located.

    此选项仅在线命令行中接受,而不在选项文件中使用。在使用 systemd 的平台上,可以在 MYSQLD_OPTS 的值中指定该值。参见 第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。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 MYSQLD_OPTS. See Section 2.5.9, “Managing MySQL Server with systemd”.

  • --log-error=file_name --log-error=file_name

    命令行格式Command-Line Format --log-error=file_name--log-error=file_name
    类型Type 文件名File name

    将错误日志写入指定的文件。参见 第 7.4.2 节,“错误日志”。Write the error log to the given file. See Section 7.4.2, “The Error Log”.

  • --mysqld-safe-log-timestamps

    命令行格式Command-Line Format --mysqld-safe-log-timestamps=type--mysqld-safe-log-timestamps=type
    类型Type 枚举Enumeration
    默认值Default Value utc
    有效值Valid Values

    systemsystem

    hyphen

    legacy

    此选项控制 mysqld_safe 生成的日志输出中的时间戳格式。以下列表描述了允许的值。对于任何其他值,mysqld_safe 会记录警告并使用 UTC 格式。This option controls the format for timestamps in log output produced by mysqld_safe. The following list describes the permitted values. For any other value, mysqld_safe logs a warning and uses UTC format.

    • UTC, utc

      ISO 8601 UTC 格式(与服务器的 --log_timestamps=UTC 相同)。这是默认设置。ISO 8601 UTC format (same as --log_timestamps=UTC for the server). This is the default.

    • SYSTEM, system

      ISO 8601 本地时间格式(与服务器的 --log_timestamps=SYSTEM 相同)。ISO 8601 local time format (same as --log_timestamps=SYSTEM for the server).

    • HYPHEN, hyphen

      YY-MM-DD h:mm:ss 格式,如 mysqld_safe 在 MySQL 5.6 中使用。YY-MM-DD h:mm:ss format, as in mysqld_safe for MySQL 5.6.

    • LEGACY, legacy

      YYMMDD hh:mm:ss 格式,如 MySQL 5.6 之前的 mysqld_safe 中所示。YYMMDD hh:mm:ss format, as in mysqld_safe prior to MySQL 5.6.

  • --malloc-lib=[lib_name]

    命令行格式Command-Line Format --malloc-lib=[lib-name]
    类型Type 字符串String

    用于内存分配的库名称,以替代系统的 malloc() 库。该选项的值必须是以下目录之一:/usr/lib、/usr/lib64、/usr/lib/i386-linux-gnu 或 /usr/lib/x86_64-linux-gnu。The name of the library to use for memory allocation instead of the system malloc() library. 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.

    --malloc-lib 选项的工作原理是通过修改 LD_PRELOAD 环境变量来影响动态链接,从而使加载器在 mysqld 运行时能够找到内存分配库: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 不会被修改,并且不会尝试使用 tcmalloc。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.

    • 在 MySQL 8.0.21 之前,如果选项指定为 --malloc-lib=tcmalloc,mysqld_safe 会在 /usr/lib 中查找 tcmalloc 库。如果找到 tcmalloc,其路径名将被添加到 mysqld 的 LD_PRELOAD 值的开头。如果未找到 tmalloc,mysqld_safe 将因错误而中止。Prior to MySQL 8.0.21, if the option is given as --malloc-lib=tcmalloc, mysqld_safe looks for a tcmalloc library in /usr/lib. If tmalloc is found, its path name is added to the beginning of the LD_PRELOAD value for mysqld. If tcmalloc is not found, mysqld_safe aborts with an error.

      从 MySQL 8.0.21 开始,tcmalloc 不是 --malloc-lib 选项允许的值。As of MySQL 8.0.21, tcmalloc is not a permitted value for the --malloc-lib option.

    • 如果选项指定为 --malloc-lib=/path/to/some/library,该完整路径将被添加到 LD_PRELOAD 值的开头。如果完整路径指向一个不存在或不可读的文件,mysqld_safe 将因错误而中止。If the option is given as --malloc-lib=/path/to/some/library, that full path is added to the beginning of the LD_PRELOAD value. If the full path points to a nonexistent or unreadable file, mysqld_safe aborts with an error.

    • 对于 mysqld_safe 将路径名添加到 LD_PRELOAD 的情况,它会将该路径添加到变量已有值的开头。For cases where mysqld_safe adds a path name to LD_PRELOAD, it adds the path to the beginning of any existing value the variable already has.

    Note

    在使用 systemd 管理服务器的系统上,mysqld_safe 不可用。相反,需要通过在 /etc/sysconfig/mysql 中设置 LD_PRELOAD 来指定分配库。On systems that manage the server using systemd, mysqld_safe is not available. Instead, specify the allocation library by setting LD_PRELOAD in /etc/sysconfig/mysql.

    Linux 用户可以在任何安装了 tcmalloc 包的 /usr/lib 平台上使用 libtcmalloc_minimal.so 库,只需在 my.cnf 文件中添加以下行:Linux users can use the 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:

    [mysqld_safe]
    malloc-lib=tcmalloc
    

    要使用特定的 tcmalloc 库,请指定其完整路径名。例如:To use a specific tcmalloc library, specify its full path name. Example:

    [mysqld_safe]
    malloc-lib=/opt/lib/libtcmalloc_minimal.so
    
  • --mysqld=prog_name --mysqld=prog_name

    命令行格式Command-Line Format --mysqld=file_name--mysqld=file_name
    类型Type 文件名File name

    要启动的服务器程序的名称(在 ledir 目录中)。如果您使用 MySQL 二进制分发版但数据目录位于二进制分发版之外,则需要此选项。如果 mysqld_safe 找不到服务器,请使用 --ledir 选项指示服务器所在目录的路径名。The name of the server program (in the ledir directory) that you want to start. This option is needed if you use the MySQL binary distribution but have the data directory outside of the binary distribution. If mysqld_safe cannot find the server, use the --ledir option to indicate the path name to the directory where the server is located.

    此选项仅在线命令行中接受,而不在选项文件中使用。在使用 systemd 的平台上,可以在 MYSQLD_OPTS 的值中指定该值。参见 第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。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 MYSQLD_OPTS. See Section 2.5.9, “Managing MySQL Server with systemd”.

  • --mysqld-version=suffix --mysqld-version=suffix

    命令行格式Command-Line Format --mysqld-version=suffix--mysqld-version=suffix
    类型Type 字符串String

    此选项类似于 --mysqld 选项,但您只需指定服务器程序名的后缀。基名假定为 mysqld。例如,如果您使用 --mysqld-version=debug,mysqld_safe 会在 ledir 目录中启动 mysqld-debug 程序。如果 --mysqld-version 的参数为空,mysqld_safe 会使用 mysqld 在 ledir 目录中。This option is similar to the --mysqld option, but you specify only the suffix for the server program name. The base name is assumed to be mysqld. For example, if you use --mysqld-version=debug, mysqld_safe starts the mysqld-debug program in the ledir directory. If the argument to --mysqld-version is empty, mysqld_safe uses mysqld in the ledir directory.

    此选项仅在线命令行中接受,而不在选项文件中使用。在使用 systemd 的平台上,可以在 MYSQLD_OPTS 的值中指定该值。参见 第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。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 MYSQLD_OPTS. See Section 2.5.9, “Managing MySQL Server with systemd”.

  • --nice=priority --nice=priority

    命令行格式Command-Line Format --nice=priority--nice=priority
    类型Type 数字Numeric

    使用 nice 程序将服务器的调度优先级设置为给定值。Use the nice program to set the server's scheduling priority to the given value.

  • --no-defaults

    命令行格式Command-Line Format --no-defaults--no-defaults
    类型Type 字符串String

    不要读取任何选项文件。如果程序启动因从选项文件读取未知选项而失败,可以使用 --no-defaults 来阻止它们被读取。如果使用,此选项必须是命令行中的第一个选项。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.

    有关此选项文件选项及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about this and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.

  • --open-files-limit=count --open-files-limit=count

    命令行格式Command-Line Format --open-files-limit=count--open-files-limit=count
    类型Type 字符串String

    mysqld 应能打开的文件数量。该选项值会传递给 ulimit -n。The number of files that mysqld should be able to open. The option value is passed to ulimit -n.

    Note

    您必须以 root 身份启动 mysqld_safe 才能使其正常工作。You must start mysqld_safe as root for this to function properly.

  • --pid-file=file_name --pid-file=file_name

    命令行格式Command-Line Format --pid-file=file_name--pid-file=file_name
    类型Type 文件名File name

    mysqld 应使用其进程 ID 文件的路径名。The path name that mysqld should use for its process ID file.

  • --plugin-dir=dir_name --plugin-dir=dir_name

    命令行格式Command-Line Format --plugin-dir=dir_name--plugin-dir=dir_name
    类型Type 目录名称Directory name

    插件目录的路径名称。The path name of the plugin directory.

  • --port=port_num --port=port_num

    命令行格式Command-Line Format --port=number--port=number
    类型Type 数字Numeric

    服务器在监听 TCP/IP 连接时应使用的端口号。除非服务器由操作系统 root 用户启动,否则端口号必须为 1024 或更高。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 root operating system user.

  • --skip-kill-mysqld

    命令行格式Command-Line Format --skip-kill-mysqld

    启动时不要尝试终止孤立的 mysqld 进程。此选项仅在 Linux 上有效。Do not try to kill stray mysqld processes at startup. This option works only on Linux.

  • --socket=path --socket=path

    命令行格式Command-Line Format --socket=file_name--socket=file_name
    类型Type 文件名File name

    服务器在侦听本地连接时应使用的 Unix 套接字文件。The Unix socket file that the server should use when listening for local connections.

  • --syslog, --skip-syslog

    命令行格式Command-Line Format --syslog
    已弃用Deprecated 是Yes
    命令行格式Command-Line Format --skip-syslog
    已弃用Deprecated 是Yes

    --syslog 会使错误信息在支持 logger 程序的系统上发送到 syslog。--skip-syslog 则抑制 syslog 的使用;消息会被写入错误日志文件。--syslog causes error messages to be sent to syslog on systems that support the logger program. --skip-syslog suppresses the use of syslog; messages are written to an error log file.

    当 syslog 用于错误记录时,所有日志消息都会使用 daemon.err 设施/严重性等级。When syslog is used for error logging, the daemon.err facility/severity is used for all log messages.

    使用这些选项来控制 mysqld 日志记录已被弃用。要将错误日志输出写入系统日志,请使用 第 7.4.2.8 节,“错误日志记录到系统日志” 中的说明。要控制日志设施,请使用服务器 log_syslog_facility 系统变量。Using these options to control mysqld logging is deprecated. To write error log output to the system log, use the instructions at Section 7.4.2.8, “Error Logging to the System Log”. To control the facility, use the server log_syslog_facility system variable.

  • --syslog-tag=tag

    命令行格式Command-Line Format --syslog-tag=tag--syslog-tag=tag
    已弃用Deprecated 是Yes

    对于记录到 syslog,来自 mysqld_safe 和 mysqld 的消息分别以 mysqld_safe 和 mysqld 作为标识符。要为标识符指定后缀,请使用 --syslog-tag=tag,它会将标识符修改为 mysqld_safe-tag 和 mysqld-tag。For logging to syslog, messages from mysqld_safe and mysqld are written with identifiers of mysqld_safe and mysqld, respectively. To specify a suffix for the identifiers, use --syslog-tag=tag, which modifies the identifiers to be mysqld_safe-tag and mysqld-tag.

    使用此选项来控制 mysqld 日志记录已被弃用。请改用服务器 log_syslog_tag 系统变量。参见 第 7.4.2.8 节,“将错误记录到系统日志”。Using this option to control mysqld logging is deprecated. Use the server log_syslog_tag system variable instead. See Section 7.4.2.8, “Error Logging to the System Log”.

  • --timezone=timezone --timezone=timezone

    命令行格式Command-Line Format --timezone=timezone--timezone=timezone
    类型Type 字符串String

    将 TZ 时区环境变量设置为给定的选项值。有关合法时区规范格式,请查阅您的操作系统文档。Set the TZ time zone environment variable to the given option value. Consult your operating system documentation for legal time zone specification formats.

  • --user={user_name|user_id} --user={user_name|user_id}

    命令行格式Command-Line Format --user={user_name|user_id}--user={user_name|user_id}
    类型Type 字符串String
    类型Type 数字Numeric

    或数字用户 IDmysqld的用户身份运行user_name服务器user_id. (“用户”在此上下文中指的是系统登录账户,而不是授予表中列出的 MySQL 用户。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.)

如果你使用 mysqld_safe 并带上 --defaults-file 或 --defaults-extra-file 选项来指定配置文件,那么该选项必须是命令行中的第一个选项,否则配置文件将不会被使用。例如,以下命令不会使用指定的配置文件: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. 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

mysqld_safe 脚本的编写方式通常可以启动从 MySQL 源码或二进制分发版本安装的服务器,即使这些类型的分发版本通常会将服务器安装在略有不同的位置。(参见 第 2.1.5 节,“安装布局”。)mysqld_safe 期望以下条件之一为真: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. (See Section 2.1.5, “Installation Layouts”.) mysqld_safe expects one of the following conditions to be true:

  • 服务器和数据库可以相对于工作目录(即从中调用 mysqld_safe 的目录)找到。对于二进制发行版,mysqld_safe 会在其工作目录下查找 bin 和 data 目录。对于源码发行版,它会查找 libexec 和 var 目录。如果你从 MySQL 安装目录执行 mysqld_safe(例如,对于二进制发行版为 /usr/local/mysql),则应满足此条件。The server and databases can be found relative to the working directory (the directory from which mysqld_safe is invoked). For binary distributions, mysqld_safe looks under its working directory for bin and data directories. For source distributions, it looks for libexec and var directories. This condition should be met if you execute mysqld_safe from your MySQL installation directory (for example, /usr/local/mysql for a binary distribution).

  • 如果无法在工作目录中找到服务器和数据库,mysqld_safe 会尝试通过绝对路径名找到它们。典型位置是 /usr/local/libexec 和 /usr/local/var。实际位置取决于构建发行版时配置的值。如果 MySQL 安装在配置时指定的位置,这些位置应该是正确的。If the server and databases cannot be found relative to the working directory, mysqld_safe attempts to locate them by absolute path names. Typical locations are /usr/local/libexec and /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.

因为 mysqld_safe 会尝试从它自己的工作目录查找服务器和数据库,所以你可以在任何地方安装 MySQL 的二进制发行版,只要你从 MySQL 安装目录运行 mysqld_safe: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:

cd mysql_installation_directory
bin/mysqld_safe &

如果 mysqld_safe 失败,即使从 MySQL 安装目录调用,也请指定 --ledir 和 --datadir 选项,以指示服务器和数据库在系统中的所在目录。If 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.

mysqld_safe 试图使用 sleep 和 date 系统工具来确定它每秒尝试启动的次数。如果这些工具存在,并且每秒尝试启动的次数大于 5 次,mysqld_safe 会在再次启动前等待 1 秒钟。这是为了防止在重复失败的情况下造成 CPU 过度使用。(Bug #11761530, Bug #54035)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, 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)

当你使用 mysqld_safe 来启动 mysqld 时,mysqld_safe 会安排自身和 mysqld 的错误(和通知)消息发送到相同的目的地。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 选项可用于控制这些消息的目的地:There are several mysqld_safe options for controlling the destination of these messages:

  • --log-error=file_name: 将错误信息写入指定的错误文件。--log-error=file_name: Write error messages to the named error file.

  • --syslog: 在支持 logger 程序的系统上,将错误信息写入 syslog。--syslog: Write error messages to syslog on systems that support the logger program.

  • --skip-syslog:不要将错误信息写入 syslog。信息会被写入默认的错误日志文件(数据目录中的 host_name.err),或者如果提供了 --log-error 选项,则写入指定文件。--skip-syslog: Do not write error messages to syslog. Messages are written to the default error log file (host_name.err in the data directory), or to a named file if the --log-error option is given.

如果没有提供这些选项,则默认值为 --skip-syslog。If none of these options is given, the default is --skip-syslog.

当 mysqld_safe 写入消息时,通知会发送到日志目标(syslog 或错误日志文件)以及 stdout。错误会发送到日志目标和 stderr。When 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

通过 mysqld 从 mysqld_safe 控制日志记录已被弃用。请改为使用服务器的原生 syslog 支持。有关更多信息,请参阅 第 7.4.2.8 节,“将错误记录到系统日志”。Controlling mysqld logging from mysqld_safe is deprecated. Use the server's native syslog support instead. For more information, see Section 7.4.2.8, “Error Logging to the System Log”.