MySQL 8.0 参考手册  / 第 4 章 MySQL 程序  /  4.10 MySQL 中的 Unix 信号处理

4.10 MySQL 中的 Unix 信号处理

在 Unix 和类 Unix 系统上,进程可以是root系统帐户或拥有该进程的系统帐户发送给它的信号的接收者。可以使用kill命令发送信号。一些命令解释器将某些键序列与信号相关联,例如 Control+C发送SIGINT 信号。本节介绍 MySQL 服务器和客户端程序如何响应信号。

服务器对信号的响应

mysqld响应信号如下:

  • SIGTERM导致服务器关闭。这就像在 SHUTDOWN不必连接到服务器的情况下执行语句(关闭服务器需要具有 SHUTDOWN特权的帐户)。

  • SIGHUP导致服务器重新加载授权表并刷新表、日志、线程缓存和主机缓存。这些动作就像FLUSH语句的各种形式。发送信号可以在无需连接到服务器的情况下执行刷新操作,这需要一个 MySQL 帐户具有足够的权限来执行这些操作。服务器还将状态报告写入具有以下格式的错误日志:

    Status information:
    
    Current dir: /var/mysql/data/
    Running threads: 4  Stack size: 262144
    Current locks:
    lock: 0x7f742c02c0e0:
    
    lock: 0x2cee2a20:
    :
    lock: 0x207a080:
    
    Key caches:
    default
    Buffer_size:       8388608
    Block_size:           1024
    Division_limit:        100
    Age_limit:             300
    blocks used:             4
    not flushed:             0
    w_requests:              0
    writes:                  0
    r_requests:              8
    reads:                   4
    
    handler status:
    read_key:           13
    read_next:           4
    read_rnd             0
    read_first:         13
    write:               1
    delete               0
    update:              0
    
    Table status:
    Opened tables:        121
    Open tables:          114
    Open files:            18
    Open streams:           0
    
    Memory status:
    <malloc version="1">
    <heap nr="0">
    <sizes>
      <size from="17" to="32" total="32" count="1"/>
      <size from="33" to="48" total="96" count="2"/>
      <size from="33" to="33" total="33" count="1"/>
      <size from="97" to="97" total="6014" count="62"/>
      <size from="113" to="113" total="904" count="8"/>
      <size from="193" to="193" total="193" count="1"/>
      <size from="241" to="241" total="241" count="1"/>
      <size from="609" to="609" total="609" count="1"/>
      <size from="16369" to="16369" total="49107" count="3"/>
      <size from="24529" to="24529" total="98116" count="4"/>
      <size from="32689" to="32689" total="32689" count="1"/>
      <unsorted from="241" to="7505" total="7746" count="2"/>
    </sizes>
    <total type="fast" count="3" size="128"/>
    <total type="rest" count="84" size="195652"/>
    <system type="current" size="690774016"/>
    <system type="max" size="690774016"/>
    <aspace type="total" size="690774016"/>
    <aspace type="mprotect" size="690774016"/>
    </heap>
    :
    <total type="fast" count="85" size="5520"/>
    <total type="rest" count="116" size="316820"/>
    <total type="mmap" count="82" size="939954176"/>
    <system type="current" size="695717888"/>
    <system type="max" size="695717888"/>
    <aspace type="total" size="695717888"/>
    <aspace type="mprotect" size="695717888"/>
    </malloc>
    
    Events status:
    LLA = Last Locked At  LUA = Last Unlocked At
    WOC = Waiting On Condition  DL = Data Locked
    
    Event scheduler status:
    State      : INITIALIZED
    Thread id  : 0
    LLA        : n/a:0
    LUA        : n/a:0
    WOC        : NO
    Workers    : 0
    Executed   : 0
    Data locked: NO
    
    Event queue status:
    Element count   : 0
    Data locked     : NO
    Attempting lock : NO
    LLA             : init_queue:95
    LUA             : init_queue:103
    WOC             : NO
    Next activation : never
  • SIGINT normally is ignored by the server. Starting the server with the --gdb option installs an interrupt handler for SIGINT for debugging purposes. See Section 5.8.1.4, “Debugging mysqld under gdb”.

Client Response to Signals

MySQL client programs respond to signals as follows:

  • The mysql client interprets SIGINT (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-ignore option to ignore SIGINT signals.

  • 默认情况下,使用 MySQL 客户端库的客户端程序会阻止 SIGPIPE信号。这些变化是可能的: