在 Unix 及类 Unix 系统中,进程可以接收由 root 系统账户或拥有该进程的系统账户发送给它的信号。信号可以使用 kill 命令发送。一些命令解释器将特定的按键序列与信号关联,例如 Control+C 用于发送 SIGINT 信号。本节描述了 MySQL 服务器和客户端程序如何响应信号。On Unix and Unix-like systems, a process can be the recipient of
signals sent to it by the root system account
or the system account that owns the process. Signals can be sent
using the kill command. Some command
interpreters associate certain key sequences with signals, such as
Control+C to send a SIGINT
signal. This section describes how the MySQL server and client
programs respond to signals.
mysqld 对信号的响应如下:mysqld responds to signals as follows:
SIGTERM会导致服务器关闭。这类似于执行一个SHUTDOWN语句,而无需连接到服务器(对于关闭操作,需要具有SHUTDOWN权限的账户)。SIGTERMcauses the server to shut down. This is like executing aSHUTDOWNstatement without having to connect to the server (which for shutdown requires an account that has theSHUTDOWNprivilege).SIGHUP会导致服务器重新加载权限表并刷新表、日志、线程缓存和主机缓存。这些操作类似于各种形式的FLUSH语句。发送该信号可以在不必连接到服务器的情况下执行刷新操作,而连接服务器通常需要具有足够权限的 MySQL 账户。SIGHUPcauses the server to reload the grant tables and to flush tables, logs, the thread cache, and the host cache. These actions are like various forms of theFLUSHstatement. Sending the signal enables the flush operations to be performed without having to connect to the server, which requires a MySQL account that has privileges sufficient for those operations.SIGUSR1会导致服务器刷新错误日志、通用查询日志和慢查询日志。SIGUSR1的一个用途是实现日志轮换而无需连接到服务器,这需要一个具有足够权限进行这些操作的 MySQL 账户。有关日志轮换的信息,请参见 第 7.4.6 节,“服务器日志维护”。SIGUSR1causes the server to flush the error log, general query log, and slow query log. One use forSIGUSR1is to implement log rotation without having to connect to the server, which requires a MySQL account that has privileges sufficient for those operations. For information about log rotation, see Section 7.4.6, “Server Log Maintenance”.服务器对
SIGUSR1的响应是对SIGHUP的响应的一个子集,使得SIGUSR1可以被用作一个更“轻量级”的信号,用于刷新某些日志而不产生其他SIGHUP影响,如刷新线程和主机缓存以及向错误日志写入状态报告。The server response toSIGUSR1is a subset of the response toSIGHUP, enablingSIGUSR1to be used as a more “lightweight” signal that flushes certain logs without the otherSIGHUPeffects such as flushing the thread and host caches and writing a status report to the error log.SIGINT通常会被服务器忽略。使用--gdb选项启动服务器会为调试目的安装SIGINT中断处理程序。参见 第 7.9.1.4 节,“在 gdb 下调试 mysqld”。SIGINTnormally is ignored by the server. Starting the server with the--gdboption installs an interrupt handler forSIGINTfor debugging purposes. See Section 7.9.1.4, “Debugging mysqld under gdb”.
MySQL 客户端程序对信号的响应如下:MySQL client programs respond to signals as follows:
mysql 客户端将
SIGINT(通常是输入 Control+C 的结果)解释为中断当前语句(如果有的话)的指令,或者取消任何部分输入行。可以使用--sigint-ignore选项来忽略SIGINT信号,从而禁用此行为。The mysql client interpretsSIGINT(typically the result of typing Control+C) as instruction to interrupt the current statement if there is one, or to cancel any partial input line otherwise. This behavior can be disabled using the--sigint-ignoreoption to ignoreSIGINTsignals.使用 MySQL 客户端库的客户端程序默认会阻塞
SIGPIPE信号。可能存在以下变体:Client programs that use the MySQL client library blockSIGPIPEsignals by default. These variations are possible:客户端可以安装自己的
SIGPIPE处理程序以覆盖默认行为。参见 编写 C API 多线程客户端程序。Client can install their ownSIGPIPEhandler to override the default behavior. See Writing C API Threaded Client Programs.客户端可以通过在连接时向
mysql_real_connect()指定CLIENT_IGNORE_SIGPIPE选项来防止安装SIGPIPE处理程序。参见 mysql_real_connect()。Clients can prevent installation ofSIGPIPEhandlers by specifying theCLIENT_IGNORE_SIGPIPEoption tomysql_real_connect()at connect time. See mysql_real_connect().