Oracle Linux上使用MySQL卡死的问题处理(时间变化导致MySQL hung up)

本文主要是介绍Oracle Linux上使用MySQL卡死的问题处理(时间变化导致MySQL hung up),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

预先操作

  1. 打开MySQL的general log, 方便排查
    临时一次: mysql -uroot -p 进入,set global general_log='ON';
    永久: MySQL配置文件, /etc/my.cnf 在[mysqld]下添加 general-log=1
    默认日志位置: /var/lib/mysql/localhost.log

  2. 打开events_statements_history 历史语句事件表

    update performance_schema.setup_consumers set ENABLED = 'YES' where NAME='events_statements_history';
    

复现MySQL卡死的情形, 并检查相关日志, 处理问题

  1. mysql -uroot -p 进入MySQL

  2. 查看事务卡住前10秒的SQL语句信息

    mysql> SELECT ->     ps.id AS processlist_id,->     trx_started,->     trx_isolation_level,->     esh.EVENT_ID,->     esh.TIMER_WAIT,->     esh.event_name AS EVENT_NAME,->     esh.sql_text AS sql1,->     esh.RETURNED_SQLSTATE,->     esh.MYSQL_ERRNO,->     esh.MESSAGE_TEXT,->     esh.ERRORS,->     esh.WARNINGS-> FROM->     information_schema.innodb_trx trx->         JOIN->     information_schema.processlist ps ON trx.trx_mysql_thread_id = ps.id->         LEFT JOIN->     performance_schema.threads th ON th.processlist_id = trx.trx_mysql_thread_id->         LEFT JOIN->     performance_schema.events_statements_history esh ON esh.thread_id = th.thread_id-> WHERE->     trx.trx_started < CURRENT_TIME - INTERVAL 10 SECOND->         AND ps.USER != 'SYSTEM_USER'-> ORDER BY esh.EVENT_ID;
    
  3. 输入SHOW ENGINE INNODB STATUS\G, 查看是否有死锁, 是否有事务卡住

    本次异常部分:
    ------------
    TRANSACTIONS
    ------------
    ---TRANSACTION 8548, ACTIVE 18 sec starting index read
    mysql tables in use 1, locked 1
    LOCK WAIT 2 lock struct(s), heap size 1136, 1 row lock(s)
    MySQL thread id 100, OS thread handle 139649020675840, query id 5122 localhost vmi updating
    UPDATE `django_session` SET `session_data` = 'session date', `expire_date` = '2019-12-02 06:22:38.968049' WHERE `django_session`.`session_key` = 'c6721mjofbqdc8fktku48ek1x16qbfbi'
    ------- TRX HAS BEEN WAITING 18 SEC FOR THIS LOCK TO BE GRANTED:
    RECORD LOCKS space id 162 page no 4 n bits 72 index PRIMARY of table `vmi`.`django_session` trx id 8548 lock_mode X locks rec but not gap waiting
    Record lock, heap no 6 PHYSICAL RECORD: n_fields 5; compact format; info bits 00: len 30; hex 63363732316d6a6f666271646338666b746b753438656b31783136716266; asc c6721mjofbqdc8fktku48ek1x16qbf; (total 32 bytes);1: len 6; hex 000000002162; asc     !b;;2: len 7; hex 0100000141137f; asc     A  ;;3: len 30; hex 5a5463314e4463775a544130596a63344e6a426a4d6a63324d446b795a57; asc ZTc1NDcwZTA0Yjc4NjBjMjc2MDkyZW; (total 252 bytes);4: len 8; hex 99a4c465a20b7899; asc    e  x ;;------------------
    ---TRANSACTION 8547, ACTIVE 19 sec starting index read
    mysql tables in use 1, locked 1
    LOCK WAIT 2 lock struct(s), heap size 1136, 1 row lock(s)
    MySQL thread id 88, OS thread handle 139649022445312, query id 5119 localhost vmi updating
    UPDATE `django_session` SET `session_data` = 'session data', `expire_date` = '2019-12-02 06:22:37.552609' WHERE `django_session`.`session_key` = 'c6721mjofbqdc8fktku48ek1x16qbfbi'
    ------- TRX HAS BEEN WAITING 19 SEC FOR THIS LOCK TO BE GRANTED:
    RECORD LOCKS space id 162 page no 4 n bits 72 index PRIMARY of table `vmi`.`django_session` trx id 8547 lock_mode X locks rec but not gap waiting
    Record lock, heap no 6 PHYSICAL RECORD: n_fields 5; compact format; info bits 00: len 30; hex 63363732316d6a6f666271646338666b746b753438656b31783136716266; asc c6721mjofbqdc8fktku48ek1x16qbf; (total 32 bytes);1: len 6; hex 000000002162; asc     !b;;2: len 7; hex 0100000141137f; asc     A  ;;3: len 30; hex 5a5463314e4463775a544130596a63344e6a426a4d6a63324d446b795a57; asc ZTc1NDcwZTA0Yjc4NjBjMjc2MDkyZW; (total 252 bytes);4: len 8; hex 99a4c465a20b7899; asc    e  x ;;------------------
    ---TRANSACTION 8546, ACTIVE (PREPARED) 22 sec
    2 lock struct(s), heap size 1136, 1 row lock(s), undo log entries 1
    MySQL thread id 96, OS thread handle 139649020970752, query id 5116 localhost vmi starting
    commit
    --------
    

    没有 LATEST DETECTED DEADLOCK 列, 只有TRANSACTIONS列, 且显示隔离级别已经是READ COMMITTED, 查询时不会锁表,不会导致update卡住。
    说明没有发生死锁,只是事务hung up.
    复制卡住的事务, 到general log 中搜索, 排查前后的SQL语句, 发现发生hung up的前后时间发生变化, 网上有资料显示时间变化会导致MySQL卡住.

排查时间变化的原因
  1. /var/log/message 日志中显示重启之后server有两次时间变化, 对比正常的server只有一次"Time has been changed", 这一次是执行启动之后的时间同步脚本产生的.

  2. 新建一台没有装我们服务的Oracle Linux Server, 发现每次reboot, Server都会有时间变化. 无论重启前是否设置硬件时间为系统时间hwclock --systohc.

    [root@localhost ~]# timedatectlLocal time: Wed 2019-12-04 16:44:49 CSTUniversal time: Wed 2019-12-04 08:44:49 UTC #国际统一时钟RTC time: Wed 2019-12-04 08:44:49 #硬件时钟Time zone: Asia/Shanghai (CST, +0800)NTP enabled: yes
    NTP synchronized: yesRTC in local TZ: no DST active: n/a
    

    reboot之后Universal time会变, 改变时message里面的记录:

    Dec  3 17:46:59 localhost systemd-logind: Watching system buttons on /dev/input/event0 (Power Button)
    Dec  3 17:46:59 localhost systemd-logind: New seat seat0.
    Dec  3 17:46:59 localhost systemd: Started Dump dmesg to /var/log/dmesg.
    Dec  3 17:46:59 localhost rsyslogd: [origin software="rsyslogd" swVersion="8.24.0" x-pid="6113" x-info="http://www.rsyslog.com"] start
    Dec  3 17:46:59 localhost systemd: Started System Logging Service.
    Dec  3 17:46:59 localhost systemd: Started Resets System Activity Logs.
    Dec  3 17:46:59 localhost systemd: Started GSSAPI Proxy Daemon.
    Dec  3 17:46:59 localhost systemd: Reached target NFS client services.
    Dec  3 17:46:59 localhost systemd: Starting NFS client services.
    Dec  3 17:46:59 localhost journal: Pref_Init: Using '/etc/vmware-tools/vgauth.conf' as preferences filepath
    Dec  3 17:46:59 localhost polkitd[6122]: Started polkitd version 0.112
    `Dec  3 17:46:59 localhost journal: Core dump limit set to -1`
    `Dec  4 01:39:08 localhost systemd: Time has been changed`
    Dec  4 01:39:08 localhost systemd: Started Authorization Manager.
    Dec  4 01:39:08 localhost systemd: Starting firewalld - dynamic firewall daemon...
    Dec  4 01:39:09 localhost systemd: Started firewalld - dynamic firewall daemon.
    Dec  4 01:39:09 localhost systemd: Reached target Network (Pre).
    Dec  4 01:39:09 localhost systemd: Starting Network (Pre).
    Dec  4 01:39:09 localhost systemd: Dependency failed for Network Manager Wait Online.
    

    reboot之后,重启时系统时间改变(7小时52分)这个问题,目前没有找到原因。

解决办法:

  1. 在启动时再init.d中设置脚本, 先用ntpdate同步时间. 此方法有问题在于,不能控制脚本执行的时间在本身系统时间变化之后,所以不可行。

    • 自启动的服务:

      server1:~ # systemctl cat set_my_clock.service
      # /usr/lib/systemd/system/set_my_clock.service
      [Unit]
      Description=Syncing system and hardware clock[Service]
      Type=oneshot
      ExecStart=/etc/init.d/set_my_clock start
      ExecStop=/etc/init.d/set_my_clock stop
      RemainAfterExit=true[Install]
      WantedBy=basic.target
    • 开机自启动的脚本

      # cat /etc/init.d/set_my_clock
      #!/bin/bash
      set -x
      case "$1" instart|stop)echo "Set Sys time according to Hardware Clock";# This will force sync the local system clock with NTP server/sbin/ntpdate -u 192.168.1.00 192.168.1.101;# This will sync our hwclock with the system clock time/sbin/hwclock --systohc;;;*)echo "Usage: $0 {start|stop}"exit 1;;
      esacecho "done !"
      exit 0
      
    1. 启用这个服务

      # systemctl enable set_my_clock.service
      
  2. 在同步时间之前先停止我们的服务,等到同步完成,再启动我们的服务。

    systemctl stop ntpd
    SERVER=pool.ntp.org
    if ntpdate -t 15 ${SERVER}; then # -t 15:超时时间为15秒echo "sync time succeed"
    elseecho "sync time failed"
    fi
    hwclock --systohc #将硬件时钟调整为与目前的系统时钟一致。
    systemctl start ntpd
    brctl stp virbr0 off
    timedatectl set-local-rtc 0 #0: 将你的硬件时钟设置为协调世界时(UTC)1: 将硬件时钟设置为本地时区:
    

这篇关于Oracle Linux上使用MySQL卡死的问题处理(时间变化导致MySQL hung up)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/900639

相关文章

Ubuntu中远程连接Mysql数据库的详细图文教程

《Ubuntu中远程连接Mysql数据库的详细图文教程》Ubuntu是一个以桌面应用为主的Linux发行版操作系统,这篇文章主要为大家详细介绍了Ubuntu中远程连接Mysql数据库的详细图文教程,有... 目录1、版本2、检查有没有mysql2.1 查询是否安装了Mysql包2.2 查看Mysql版本2.

Oracle数据库常见字段类型大全以及超详细解析

《Oracle数据库常见字段类型大全以及超详细解析》在Oracle数据库中查询特定表的字段个数通常需要使用SQL语句来完成,:本文主要介绍Oracle数据库常见字段类型大全以及超详细解析,文中通过... 目录前言一、字符类型(Character)1、CHAR:定长字符数据类型2、VARCHAR2:变长字符数

C++变换迭代器使用方法小结

《C++变换迭代器使用方法小结》本文主要介绍了C++变换迭代器使用方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录1、源码2、代码解析代码解析:transform_iterator1. transform_iterat

基于SpringBoot+Mybatis实现Mysql分表

《基于SpringBoot+Mybatis实现Mysql分表》这篇文章主要为大家详细介绍了基于SpringBoot+Mybatis实现Mysql分表的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录基本思路定义注解创建ThreadLocal创建拦截器业务处理基本思路1.根据创建时间字段按年进

Python3.6连接MySQL的详细步骤

《Python3.6连接MySQL的详细步骤》在现代Web开发和数据处理中,Python与数据库的交互是必不可少的一部分,MySQL作为最流行的开源关系型数据库管理系统之一,与Python的结合可以实... 目录环境准备安装python 3.6安装mysql安装pymysql库连接到MySQL建立连接执行S

C++中std::distance使用方法示例

《C++中std::distance使用方法示例》std::distance是C++标准库中的一个函数,用于计算两个迭代器之间的距离,本文主要介绍了C++中std::distance使用方法示例,具... 目录语法使用方式解释示例输出:其他说明:总结std::distance&n编程bsp;是 C++ 标准

vue使用docxtemplater导出word

《vue使用docxtemplater导出word》docxtemplater是一种邮件合并工具,以编程方式使用并处理条件、循环,并且可以扩展以插入任何内容,下面我们来看看如何使用docxtempl... 目录docxtemplatervue使用docxtemplater导出word安装常用语法 封装导出方

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

使用Jackson进行JSON生成与解析的新手指南

《使用Jackson进行JSON生成与解析的新手指南》这篇文章主要为大家详细介绍了如何使用Jackson进行JSON生成与解析处理,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 核心依赖2. 基础用法2.1 对象转 jsON(序列化)2.2 JSON 转对象(反序列化)3.