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

4.10 MySQL 中的 Unix 信号处理

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

服务器对信号的响应

mysqld响应信号如下:

  • SIGTERM导致服务器关闭。

  • 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通常被服务器忽略。使用该选项启动服务器 --gdb会安装一个中断处理程序以SIGINT用于调试目的。参见 第 5.8.1.4 节,“在 gdb 下调试 mysqld”

客户端对信号的响应

MySQL客户端程序响应信号如下:

  • mysql客户端将 (SIGINT通常是键入 Control+C的结果)解释为中断当前语句(如果有)的指令,否则取消任何部分输入行。可以使用--sigint-ignore忽略SIGINT信号的选项禁用此行为。

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