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). 安装的名称可能不同(例如mysqld或mysql)。In the following discussion, adjust the name mysql.server as appropriate for your system.在下面的讨论中,根据您的系统调整mysql.server的名称。
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.server和mysqld_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 要使用mysql.server脚本手动启动或停止服务器,请使用start
or stop
arguments:start
或stop
参数从命令行调用它:
mysql.server start mysql.server stop
mysql.server changes location to the MySQL installation directory, then invokes mysqld_safe. mysql.server将位置更改为MySQL安装目录,然后调用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. /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 要在服务器上自动启动和停止MySQL,您必须在/etc/rc*
files:/etc/rc*
文件中的适当位置添加启动和停止命令:
If you use the Linux server RPM package (如果您使用Linux服务器RPM包(MySQL-server-
), or a native Linux package installation, the mysql.server script may be installed in the VERSION
.rpm/etc/init.d
directory with the name mysqld
or mysql
. MySQL-server-VERSION.rpm
)或本机Linux包安装,mysql.server脚本可能会安装在/etc/init.d
目录中,名为mysqld
或mysql
。See Section 2.5.4, “Installing MySQL on Linux Using RPM Packages from Oracle”, for more information on the Linux RPM packages.有关Linux RPM包的更多信息,请参阅第2.5.4节,“使用Oracle的RPM包在Linux上安装MySQL”。
If you install MySQL from a source distribution or using a binary distribution format that does not install mysql.server automatically, you can install the script manually. 如果您从源发行版安装MySQL,或者使用不自动安装mysql.server
的二进制发行版格式安装MySQL,则可以手动安装脚本。It can be found in the 它可以在MySQL安装目录下的support-files
directory under the MySQL installation directory or in a MySQL source tree. support-files
目录或MySQL源代码树中找到。Copy the script to the 将脚本复制到名为mysql的/etc/init.d
directory with the name mysql and make it executable:/etc/init.d
目录中,并使其可执行:
cp mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql
After installing the script, the commands needed to activate it to run at system startup depend on your operating system. On Linux, you can use chkconfig:安装脚本后,激活它以在系统启动时运行所需的命令取决于您的操作系统。在Linux上,您可以使用chkconfig:
chkconfig --add mysql
On some Linux systems, the following command also seems to be necessary to fully enable the mysql script:在某些Linux系统上,以下命令似乎也是完全启用mysql脚本所必需的:
chkconfig --level 345 mysql on
On FreeBSD, startup scripts generally should go in 在FreeBSD上,启动脚本通常应该放在/usr/local/etc/rc.d/
. /usr/local/etc/rc.d/
中。Install the 将mysql.server
script as /usr/local/etc/rc.d/mysql.server.sh
to enable automatic startup. mysql.server
脚本安装为/usr/local/etc/rcd/mysql.server.sh
,以启用自动启动。The rc(8)
manual page states that scripts in this directory are executed only if their base name matches the *.sh
shell file name pattern. rc(8)
手册页指出,只有当此目录中的脚本的基本名称与*.sh
shell文件名模式匹配时,才会执行这些脚本。Any other files or directories present within the directory are silently ignored.目录中存在的任何其他文件或目录都会被自动忽略。
As an alternative to the preceding setup, some operating systems also use 作为上述设置的替代方案,一些操作系统还使用/etc/rc.local
or /etc/init.d/boot.local
to start additional services on startup. /etc/rc.local
或/etc/init.d/boot.local
在启动时启动其他服务。To start up MySQL using this method, append a command like the one following to the appropriate startup file:要使用此方法启动MySQL,请将以下命令附加到相应的启动文件中:
/bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'
For other systems, consult your operating system documentation to see how to install startup scripts.对于其他系统,请参阅操作系统文档,了解如何安装启动脚本。
mysql.server reads options from the mysql.server从选项文件的[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]
.[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 mysql.server只支持start
and stop
as command-line arguments.start
和stop
作为命令行参数。
Table 4.7 mysql.server Option-File Options选项文件选项
basedir | ||
---|---|---|
datadir | ||
pid-file | ||
service-startup-timeout |
The path to the MySQL installation directory.MySQL安装目录的路径。
The path to the MySQL data directory.MySQL数据目录的路径。
The path name of the file in which the server should write its process ID. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.服务器应在其中写入其进程ID的文件的路径名。除非给出绝对路径名以指定其他目录,否则服务器将在数据目录中创建文件。
If this option is not given, mysql.server uses a default value of 如果不提供此选项,
. host_name
.pidmysql.server
将使用默认值host_name.pid
。The PID file value passed to mysqld_safe overrides any value specified in the 传递给mysqld_safe的PID文件值会覆盖[mysqld_safe]
option file group. [mysqld_safe]
选项文件组中指定的任何值。Because mysql.server reads the 因为mysql.server读取的是[mysqld]
option file group but not the [mysqld_safe]
group, you can ensure that mysqld_safe gets the same value when invoked from mysql.server as when invoked manually by putting the same pid-file
setting in both the [mysqld_safe]
and [mysqld]
groups.[mysqld]
选项文件组,而不是[mysqld_safe]
组,所以通过在[mysqld_safe]
和[mysqld]
组中放置相同的pid文件设置,可以确保从mysql.server调用mysqld_safe
时得到的值与手动调用时相同。
service-startup-timeout=
seconds
How long in seconds to wait for confirmation of server startup. If the server does not start within this time, mysql.server exits with an error. 等待服务器启动确认的时间(秒)。如果服务器未在此时间内启动,mysql.server将退出并返回错误。The default value is 900. A value of 0 means not to wait at all for startup. Negative values mean to wait forever (no timeout).默认值为900。值为0表示根本不等待启动。负值表示永远等待(无超时)。