暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

4.10 MySQL中的Unix信号处理

原创 由迪 2021-03-09
799

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

服务器对信号的响应

mysqld对信号的响应如下:

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

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

    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
    
  • 从MySQL 8.0.19开始,SIGUSR1导致服务器刷新错误日志,常规查询日志和慢速查询日志。一种用途SIGUSR1是无需连接服务器即可实现日志轮转,这需要一个具有足够执行这些操作特权的MySQL帐户。有关日志轮换的信息,请参见第5.4.6节“服务器日志维护”

    服务器响应SIGUSR1是响应的一个子集SIGHUP,能够SIGUSR1被用作一个更 “轻量”是刷新某些日志中没有其他信号SIGHUP的影响,如冲洗线和主机缓存和写入错误日志的状态报告。

  • SIGINT通常服务器会忽略它。使用该--gdb选项启动服务器 会安装一个中断处理程序,以SIGINT用于调试目的。请参见 第5.9.1.4节“在gdb下调试mysqld”

客户对信号的反应

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

  • MySQL的客户端解释 SIGINT(打字的典型结果 控制+ C)作为指令中断当前的声明(如果有),或以其他方式取消任何部分输入线。可以使用--sigint-ignore忽略SIGINT信号选项禁用此行为。
  • SIGPIPE默认情况下 ,使用MySQL客户端库的客户端程序会阻止 信号。这些变化是可能的:
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论