MySQL行锁堵塞案例

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 背景 客户执行delete操作一直显示ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction 测试环境 centos7.

背景

客户执行delete操作一直显示ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

测试环境

  • centos7.4
  • MySQL5.7.25

测试步骤

session 1
root@localhost : test 05:58:52> select * from test111;
+------+
| a |
+------+
| 1 |
| 3 |
| 7 |
| 10 |
| 11 |
+------+
5 rows in set (0.00 sec)

root@localhost : test 06:06:53> begin;
Query OK, 0 rows affected (0.00 sec)

root@localhost : test 06:06:55> insert into test111 values(11);
Query OK, 1 row affected (0.00 sec)
session 2
root@localhost : (none) 06:07:07> begin;
Query OK, 0 rows affected (0.00 sec)

root@localhost : (none) 06:07:09> use test
Database changed

root@localhost : test 06:07:11> delete from test111 where a >3;
session 3
root@localhost : test 06:07:03> use sys
Database changed

root@localhost : sys 07:40:44> select * from innodb_lock_waits\G
*************************** 1. row ***************************
                wait_started: 2019-02-18 19:41:29
                    wait_age: 00:00:18
               wait_age_secs: 18
                locked_table: `test`.`test111`
                locked_index: GEN_CLUST_INDEX
                 locked_type: RECORD
              waiting_trx_id: 605682
         waiting_trx_started: 2019-02-18 19:41:29
             waiting_trx_age: 00:00:18
     waiting_trx_rows_locked: 3
   waiting_trx_rows_modified: 2
                 waiting_pid: 903466
               waiting_query: delete from test111 where a >3
             waiting_lock_id: 605682:47:3:6
           waiting_lock_mode: X
             blocking_trx_id: 605672
                blocking_pid: 903490
              blocking_query: NULL
            blocking_lock_id: 605672:47:3:6
          blocking_lock_mode: X
        blocking_trx_started: 2019-02-18 19:41:20
            blocking_trx_age: 00:00:27
    blocking_trx_rows_locked: 1
  blocking_trx_rows_modified: 1
     sql_kill_blocking_query: KILL QUERY 903490
sql_kill_blocking_connection: KILL 903490
1 row in set, 3 warnings (0.00 sec)

Warning (Code 1681): 'INFORMATION_SCHEMA.INNODB_LOCK_WAITS' is deprecated and will be removed in a future release.
Warning (Code 1681): 'INFORMATION_SCHEMA.INNODB_LOCKS' is deprecated and will be removed in a future release.
Warning (Code 1681): 'INFORMATION_SCHEMA.INNODB_LOCKS' is deprecated and will be removed in a future release.
root@localhost : sys 07:41:47> select * from sys.session where conn_id=903490\G
*************************** 1. row ***************************
                thd_id: 903532
               conn_id: 903490
                  user: root@localhost
                    db: test
               command: Sleep
                 state: NULL
                  time: 37
     current_statement: NULL
     statement_latency: NULL
              progress: NULL
          lock_latency: 128.00 us
         rows_examined: 0
             rows_sent: 0
         rows_affected: 1
            tmp_tables: 0
       tmp_disk_tables: 0
             full_scan: NO
        last_statement: insert into test111 values(11)
last_statement_latency: 406.35 us
        current_memory: 0 bytes
             last_wait: NULL
     last_wait_latency: NULL
                source: NULL
           trx_latency: NULL
             trx_state: NULL
        trx_autocommit: NULL
                   pid: 21460
          program_name: mysql
1 row in set (0.11 sec)

root@localhost : sys 07:41:57> show processlist;
+--------+------+--------------------+------+---------+------+----------+--------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+------+--------------------+------+---------+------+----------+--------------------------------+
| 903410 | root | localhost | sys | Query | 0 | starting | show processlist |
| 903466 | root | localhost | test | Query | 65 | updating | delete from test111 where a >3 |
| 903490 | root | localhost | test | Sleep | 74 | | NULL |
| 903705 | root | 10.244.2.124:44058 | test | Sleep | 1 | | NULL |
+--------+------+--------------------+------+---------+------+----------+--------------------------------+
4 rows in set (0.00 sec)
session 2
root@localhost : test 06:07:11> delete from test111 where a >3;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
29天前
Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
20 1
|
29天前
|
Java 关系型数据库 数据库连接
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
24 1
|
29天前
Mybatis+mysql动态分页查询数据案例——条件类(HouseCondition)
Mybatis+mysql动态分页查询数据案例——条件类(HouseCondition)
15 1
|
29天前
Mybatis+mysql动态分页查询数据案例——分页工具类(Page.java)
Mybatis+mysql动态分页查询数据案例——分页工具类(Page.java)
21 1
|
29天前
Mybatis+mysql动态分页查询数据案例——房屋信息的实现类(HouseDaoMybatisImpl)
Mybatis+mysql动态分页查询数据案例——房屋信息的实现类(HouseDaoMybatisImpl)
21 2
|
4月前
|
SQL 弹性计算 关系型数据库
服务器数据恢复-华为ECS云服务器mysql数据库数据恢复案例
云服务器数据恢复环境: 华为ECS云服务器,linux操作系统,mysql数据库(innodb引擎)。作为网站服务器使用。 云服务器故障: 在执行mysql数据库版本更新测试时,误将本应该在测试库上执行的sql脚本执行在生产库上了,生产库上的部分表被truncate,部分表内有少量数据被delete。 需要恢复被truncate的表以及被少量数据被delete的表。
服务器数据恢复-华为ECS云服务器mysql数据库数据恢复案例
|
29天前
Mybatis+mysql动态分页查询数据案例——工具类(MybatisUtil.java)
Mybatis+mysql动态分页查询数据案例——工具类(MybatisUtil.java)
15 1
|
1月前
|
SQL 关系型数据库 MySQL
Sqoop【付诸实践 01】Sqoop1最新版 MySQL与HDFS\Hive\HBase 核心导入导出案例分享+多个WRAN及Exception问题处理(一篇即可学会在日常工作中使用Sqoop)
【2月更文挑战第9天】Sqoop【付诸实践 01】Sqoop1最新版 MySQL与HDFS\Hive\HBase 核心导入导出案例分享+多个WRAN及Exception问题处理(一篇即可学会在日常工作中使用Sqoop)
94 7
|
1天前
|
关系型数据库 MySQL 中间件
【MySQL实战笔记】07 | 行锁功过:怎么减少行锁对性能的影响?-02 死锁和死锁检测
【4月更文挑战第19天】在高并发环境下,死锁发生在多个线程间循环等待资源时,导致无限期等待。MySQL中,死锁可通过`innodb_lock_wait_timeout`参数设置超时或`innodb_deadlock_detect`开启死锁检测来解决。默认的50s超时可能不适用于在线服务,而频繁检测会消耗大量CPU。应对热点行更新引发的性能问题,可以暂时关闭死锁检测(风险是产生大量超时),控制并发度,或通过分散记录减少锁冲突,例如将数据分拆到多行以降低死锁概率。
12 1
|
5天前
|
Java 关系型数据库 MySQL
一套java+ spring boot与vue+ mysql技术开发的UWB高精度工厂人员定位全套系统源码有应用案例
UWB (ULTRA WIDE BAND, UWB) 技术是一种无线载波通讯技术,它不采用正弦载波,而是利用纳秒级的非正弦波窄脉冲传输数据,因此其所占的频谱范围很宽。一套UWB精确定位系统,最高定位精度可达10cm,具有高精度,高动态,高容量,低功耗的应用。
一套java+ spring boot与vue+ mysql技术开发的UWB高精度工厂人员定位全套系统源码有应用案例