4.3.2 mysqld_safe — MySQL Server Startup ScriptMySQL服务器启动脚本

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添加了一些安全功能,例如在发生错误时重新启动服务器,并将运行时信息记录到错误日志中。本节稍后将介绍错误日志记录。

Note注意

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 or --mysqld-version option to mysqld_safe. 要覆盖默认行为并明确指定要运行的服务器的名称,请在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] group of an option file. 如果在命令行上指定了mysqld_safe未知的选项,则将其传递给mysqld,但如果在选项文件的[mysqld_safe]组中指定了这些选项,则忽略这些选项。See Section 4.2.2.2, “Using Option Files”.请参阅第4.2.2.2节,“使用选项文件”

mysqld_safe reads all options from the [mysqld], [server], and [mysqld_safe] sections in option files. mysqld_safe从选项文件中的[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 [safe_mysqld] sections, but to be current you should rename such sections to [mysqld_safe].为了向后兼容,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

Option Name选项名称Description描述
--basedirPath to MySQL installation directoryMySQL安装目录的路径
--core-file-sizeSize of core file that mysqld should be able to createmysqld应该能够创建的核心文件的大小
--datadirPath to data directory数据目录路径
--defaults-extra-fileRead named option file in addition to usual option files除了常规选项文件外,还读取命名选项文件
--defaults-fileRead only named option file只读命名选项文件
--helpDisplay help message and exit显示帮助消息并退出
--ledirPath to directory where server is located服务器所在目录的路径
--log-errorWrite error log to named file将错误日志写入指定文件
--malloc-libAlternative malloc library to use for mysqldmysqld使用的替代malloc库
--mysqldName of server program to start (in ledir directory)要启动的服务器程序的名称(在ledir目录中)
--mysqld-safe-log-timestampsTimestamp format for logging日志记录的时间戳格式
--mysqld-versionSuffix for server program name服务器程序名称后缀
--niceUse nice program to set server scheduling priority使用nice程序设置服务器调度优先级
--no-defaultsRead no option files不读取选项文件
--open-files-limitNumber of files that mysqld should be able to openmysqld应该能够打开的文件数
--pid-filePath name of server process ID file服务器进程ID文件的路径名
--plugin-dirDirectory where plugins are installed安装插件的目录
--portPort number on which to listen for TCP/IP connections用于侦听TCP/IP连接的端口号
--skip-kill-mysqldDo not try to kill stray mysqld processes不要试图杀死游离的mysqld进程
--skip-syslogDo not write error messages to syslog; use error log file不要将错误消息写入syslog;使用错误日志文件
--socketSocket file on which to listen for Unix socket connections用于监听Unix套接字连接的套接字文件
--syslogWrite error messages to syslog将错误消息写入系统日志
--syslog-tagTag suffix for messages written to syslog写入syslog的消息的标记后缀
--timezoneSet TZ time zone environment variable to named value将TZ时区环境变量设置为指定值
--userRun mysqld as user having name user_name or numeric user ID user_id以用户名user_name或数字用户ID user_ID的用户身份运行mysqld

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期望以下条件之一为真:

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 --ledir and --datadir options to indicate the directories in which the server and databases are located on your system.如果mysqld_safe失败,即使从MySQL安装目录调用,也要指定--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试图使用sleepdate系统实用程序来确定它每秒尝试启动的次数。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选项可以控制这些消息的目标:

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 (syslog or the error log file) and stdout. mysqld_safe写入消息时,通知会发送到日志记录目标(syslog或错误日志文件)和stdoutErrors go to the logging destination and stderr.错误将转到日志记录目标和stderr

Note注意

Controlling mysqld logging from mysqld_safe is deprecated. Use the server's native syslog support instead. 不推荐从mysqld_safe控制mysqld日志记录。请改用服务器的本机syslog支持。For more information, see Section 5.4.2.8, “Error Logging to the System Log”.有关更多信息,请参阅第5.4.2.8节,“系统日志错误记录”