4.3.3 mysql.server — MySQL Server Startup ScriptMySQL服务器启动脚本

MySQL distributions on Unix and Unix-like system include a script named mysql.server, which starts the MySQL server using mysqld_safe. Unix和类Unix系统上的MySQL发行版包含一个名为mysql.server的脚本,该脚本使用mysqld_safe启动MySQL服务器。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.它可以在Linux和Solaris等系统上使用,这些系统使用System V风格的运行目录来启动和停止系统服务。MySQL的macOS启动项也使用它。

mysql.server is the script name as used within the MySQL source tree. mysql.server是MySQL源代码树中使用的脚本名称。The installed name might be different (for example, mysqld or mysql). 安装的名称可能不同(例如mysqldmysql)。In the following discussion, adjust the name mysql.server as appropriate for your system.在下面的讨论中,根据您的系统调整mysql.server的名称。

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, mysql.server and mysqld_safe are not installed because they are unnecessary. 在这些平台上,没有安装mysql.servermysqld_safe,因为它们是不必要的。For more information, see Section 2.5.9, “Managing MySQL Server with systemd”.有关更多信息,请参阅第2.5.9节,“使用systemd管理MySQL服务器”

To start or stop the server manually using the mysql.server script, invoke it from the command line with start or stop arguments:要使用mysql.server脚本手动启动或停止服务器,请使用startstop参数从命令行调用它:

mysql.server start
mysql.server stop

mysql.server changes location to the MySQL installation directory, then invokes mysqld_safe. mysql.server将位置更改为MySQL安装目录,然后调用mysqld_safeTo 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. 要以特定用户身份运行服务器,请向全局/etc/my.cnf选项文件的[mysqld]组添加适当的user选项,如本节稍后所示。(It is possible that you must edit 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 mysqld_safe. If you do this, your modified version of mysql.server may be overwritten if you upgrade MySQL in the future; make a copy of your edited version that you can reinstall.)(如果你在非标准位置安装了MySQL的二进制发行版,你可能必须编辑mysql.server。在运行mysqld_safe之前,修改它以将位置更改为正确的目录。如果你这样做,如果你将来升级MySQL,修改后的mysqlserver版本可能会被覆盖;复制一份编辑后的版本,以便重新安装。)

mysql.server stop stops the server by sending a signal to it. mysql.server stop通过向服务器发送信号来停止服务器。You can also stop the server manually by executing mysqladmin shutdown.您还可以通过执行mysqladmin shutdown手动停止服务器。

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:要在服务器上自动启动和停止MySQL,您必须在/etc/rc*文件中的适当位置添加启动和停止命令:

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].mysql.server从选项文件的[mysqlserver][mysqld]部分读取选项。为了向后兼容,它还读取[mysql_server]部分,但要成为最新版本,您应该将这些部分重命名为[mysql.server]

You can add options for mysql.server in a global /etc/my.cnf file. 您可以在全局/etc/my.cnf文件中为mysql.server添加选项。A typical my.cnf file might look like this:一个典型的my.cnf文件可能看起来像这样:

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

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

The mysql.server script supports the options shown in the following table. mysql.server脚本支持下表所示的选项。If specified, they must be placed in an option file, not on the command line. 如果指定,则必须将它们放置在选项文件中,而不是命令行上。mysql.server supports only start and stop as command-line arguments.mysql.server只支持startstop作为命令行参数。

Table 4.7 mysql.server Option-File Options选项文件选项

Option Name选项名称Description描述Type类型
basedirPath to MySQL installation directoryMySQL安装目录的路径Directory name目录名
datadirPath to MySQL data directoryMySQL数据目录的路径Directory name目录名
pid-fileFile in which server should write its process ID服务器应在其中写入其进程ID的文件File name文件名
service-startup-timeoutHow long to wait for server startup等待服务器启动需要多长时间Integer整数