RESTART
This statement stops and restarts the MySQL server. 此语句停止并重新启动MySQL服务器。It requires the 它需要SHUTDOWN
privilege.SHUTDOWN
权限。
One use for RESTART
is when it is not possible or convenient to gain command-line access to the MySQL server on the server host to restart it. RESTART
的一个用途是当无法或不方便通过命令行访问服务器主机上的MySQL服务器来重启它时。For example, 例如,SET PERSIST_ONLY
can be used at runtime to make configuration changes to system variables that can be set only at server startup, but the server must still be restarted for those changes to take effect. SET PERSIST_ONLY
可在运行时用于对系统变量进行配置更改,这些更改只能在服务器启动时设置,但仍必须重新启动服务器才能使这些更改生效。The RESTART
statement provides a way to do so from within client sessions, without requiring command-line access on the server host.RESTART
语句提供了一种从客户端会话中执行此操作的方法,而不需要在服务器主机上进行命令行访问。
After executing a 在执行RESTART
statement, the client can expect the current connection to be lost. RESTART
语句后,客户机可以预期当前连接将丢失。If auto-reconnect is enabled, the connection is reestablished after the server restarts. 如果启用了自动重新连接,则会在服务器重新启动后重新建立连接。Otherwise, the connection must be reestablished manually.否则,必须手动重新建立连接。
A successful 成功的RESTART
operation requires mysqld to be running in an environment that has a monitoring process available to detect a server shutdown performed for restart purposes:RESTART
操作需要mysqld
在一个环境中运行,该环境中有一个可用于检测为重启目的而执行的服务器关闭的监视进程:
In the presence of a monitoring process, 在存在监视进程的情况下,RESTART
causes mysqld to terminate such that the monitoring process can determine that it should start a new mysqld instance.RESTART
会导致mysqld
终止,以便监视进程可以确定它应该启动一个新的mysqld
实例。
If no monitoring process is present, 如果不存在监控过程,则RESTART
fails with an error.RESTART
会失败并出现错误。
These platforms provide the necessary monitoring support for the 这些平台为RESTART
statement:RESTART
语句提供了必要的监控支持:
Windows, when mysqld is started as a Windows service or standalone. Windows,当mysqld
作为Windows服务或独立启动时。(mysqld forks, and one process acts as a monitor to the other, which acts as the server.)(mysqld
分叉,一个进程充当监视器,另一个进程充当服务器。)
Unix and Unix-like systems that use systemd or mysqld_safe to manage mysqld.使用systemd或mysqld_safe
管理mysqld
的Unix和类Unix系统。
To configure a monitoring environment such that mysqld enables the 要配置监控环境,以便RESTART
statement:mysqld
启用RESTART
语句,请执行以下操作:
Set the 在启动MYSQLD_PARENT_PID
environment variable to the value of the process ID of the process that starts mysqld, before starting mysqld.mysqld
之前,将MYSQLD_PARENT_PID
环境变量设置为启动mysqld
的进程的进程ID的值。
When mysqld performs a shutdown due to use of the 当RESTART
statement, it returns exit code 16.mysqld
由于使用RESTART
语句而执行关机时,它返回退出代码16。
When the monitoring process detects an exit code of 16, it starts mysqld again. 当监控进程检测到退出代码为16时,它会再次启动mysqld
。Otherwise, it exits.否则,它就会退出。
Here is a minimal example as implemented in the bash shell:下面是在bash shell中实现的一个简单示例:
#!/bin/bash
export MYSQLD_PARENT_PID=$$
export MYSQLD_RESTART_EXIT=16
while true ; do
bin/mysqld mysqld options here
if [ $? -ne $MYSQLD_RESTART_EXIT ]; then
break
fi
done
On Windows, the forking used to implement 在Windows上,用于实现RESTART
makes determining the server process to attach to for debugging more difficult. RESTART
的分叉使确定要连接以进行调试的服务器进程变得更加困难。To alleviate this, starting the server with 为了缓解这种情况,除了设置调试环境所做的其他操作外,用--gdb
suppresses forking, in addition to its other actions done to set up a debugging environment. --gdb
启动服务器会抑制分叉。In non-debug settings, 在非调试设置中,--no-monitor
may be used for the sole purpose of suppressing forking the monitor process. --no-monitor
可能仅用于抑制监视器进程分叉。For a server started with either 对于以--gdb
or --no-monitor
, executing RESTART
causes the server to simply exit without restarting.--gdb
或--no-monitor
启动的服务器,执行RESTART
会导致服务器直接退出而不重新启动。
The Com_restart
status variable tracks the number of RESTART
statements. Com_restart
状态变量跟踪RESTART
语句的数量。Because status variables are initialized for each server startup and do not persist across restarts, 因为状态变量在每次服务器启动时都会初始化,并且不会在重启期间持续存在,所以Com_restart
normally has a value of zero, but can be nonzero if RESTART
statements were executed but failed.Com_restart
的值通常为零,但如果RESTART
语句被执行但失败,则状态变量可以为非零。