MySQL的ERROR 1205错误分析
一、错误发生及原因猜测
1、错误发生
在删除 t_user 表的一条数据时,Navicat 发生长时间的无响应,然后弹出一个对话框,提示:ERROR 1205: Lock wait timeout exceeded; try restarting transaction

关闭对话框之后,数据并没有被删除。
2、原因猜测
根据错误信息可以知道,是因为锁等待超时导致的错误。那么具体到底是什么原因。
我们知道,InnoDB 引擎是支持事务的。
在使用 begin 或 start transaction 开启事务,进行更新、删除时,会对被操作的行加行级锁。
如果这个事务没有提交,而其他的事务对同一行也进行了更新、删除操作,那么这个事务是不能成功的,至于会不会出现上面的错误,还不确定。
二、错误重现
1、演示环境
|
操作系统 |
Windows 7 x64 |
|
MySQL版本 |
MySQL Community Server (GPL) 5.5.56 |
|
执行未提交事务的用户 |
system |
|
查看会话、执行删除操作的用户 |
root |
|
数据库 |
test |
|
表 |
t_user |
mysql> select * from t_user;
+----+----------+
| id | username |
+----+----------+
| 1 | a1 |
| 2 | a2 |
| 3 | a3 |
| 4 | a4 |
| 5 | a5 |
| 6 | a6 |
+----+----------+
2、错误重现
使用 A窗口 更新 id = 2 的数据
mysql> begin;
Query OK, 0 rows affected (0.00 sec) mysql> update t_user set username = 'b1' where id = 2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
在没有提交的情况下,使用 C窗口 查看当前事务,我们可以看到事务的 状态(trx_state)、行锁数(trx_rows_locked)、修改数据行数(trx_rows_modified) 等信息
mysql> select * from innodb_trx\G;
*************************** 1. row ***************************
trx_id: A023
trx_state: RUNNING
trx_started: 2018-03-11 15:30:19
trx_requested_lock_id: NULL
trx_wait_started: NULL
trx_weight: 3
trx_mysql_thread_id: 5
trx_query: NULL
trx_operation_state: NULL
trx_tables_in_use: 0
trx_tables_locked: 0
trx_lock_structs: 2
trx_lock_memory_bytes: 376
trx_rows_locked: 1
trx_rows_modified: 1
trx_concurrency_tickets: 0
trx_isolation_level: REPEATABLE READ
trx_unique_checks: 1
trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
trx_adaptive_hash_latched: 0
trx_adaptive_hash_timeout: 10000
此时再使用 B窗口 删除t_user表的数据,在删除 id = 2 的数据时,发现事务被阻塞。我们在 C窗口 查看 processlist、事务以及锁等待 情况
mysql> show full processlist;

mysql> select * from innodb_trx\G;

mysql> select * from INNODB_LOCK_WAITS\G;

当事务超时后出现1205的错误

此时,我们再查看一下 processlist、事务以及锁等待 情况,发现刚才处于 等待状态 的事务、process和锁等待已经没有了
mysql> show full processlist;
mysql> select * from INNODB_LOCK_WAITS\G;
mysql> select * from innodb_trx\G;

此时把 A窗口rollback 回来
mysql> rollback;
再查看一下processlist、事务以及锁等待情况

由此可以确定:1205 的错误是因为未提交事务对数据加了行级锁,当前事务获取同一数据行级锁超时导致的
三、解决方案
我们可以使用 show full processlist 查看未提交事务的连接的 id

可以看到这个连接的id是5
如果可以确定不是很重要的事务,我们可以使用kill命令断开这个连接。
mysql> kill 5;

如果不确定的话,还是需要沟通一下如何安全处理。
MySQL的ERROR 1205错误分析的更多相关文章
- Mysql错误: ERROR 1205: Lock wait timeout exceeded解决办法(MySQL锁表、事物锁表的处理方法)
Java执行一个SQL查询未提交,遇到1205错误. java.lang.Exception: ### Error updating database. Cause: java.sql.SQLExc ...
- Mysql错误:ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
昨晚添加完索引之后, 查询整表的时候抛出Lock wait timeout exceeded; try restarting transaction, 吓死小白的我, 为什么条件查询可以, 整表查不了 ...
- Mysql错误: ERROR 1205: Lock wait timeout exceeded; try restarting transaction
MySQL:innodb的事务锁,一个线程占用着,简单做法是:执行mysql命令: show full processlist; 然后找出查询语句的系统id:kill掉被锁住的线程id:kill 12 ...
- Mysql错误: ERROR 1205: Lock wait timeout exceeded try restarting transaction解决办法
select * from information_schema.INNODB_TRX;show full processlist;//找出目前连接的列表kill ID//根据ID kill掉
- magento后台登陆被锁定 索引报错的解决:General error: 1205 Lock wait timeout
1. magento在索引的时候用shell,有时候会报错: General error: 1205 Lock wait timeout exceeded 这个时候,是因为行锁的原因,在表中您直接用s ...
- ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
测试库一条update语句报错:ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction mysql> ...
- ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction解决办法
一.问题描述: 同事反馈线上一个表有其中一条数据无法删除,其他都正常,我拿到删数据的sql,尝试执行,报错如下: mysql> delete from facebook_posts where ...
- mysql-SQL Error: 1205, SQLState: 41000
mysql-SQL Error: 1205, SQLState: 41000——CSDN问答频道https://ask.csdn.net/questions/176492 mysql-SQL Erro ...
- ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction 表被锁的解决办法
转自:https://blog.csdn.net/mchdba/article/details/38313881 前言:朋友咨询我说执行简单的update语句失效,症状如下:mysql> upd ...
随机推荐
- hive集成kerberos
1.票据的生成 kdc服务器操作,生成用于hive身份验证的principal 1.1.创建principal # kadmin.local -q “addprinc -randkey hive/yj ...
- Redis采坑(一)——数据无法插入,内存溢出
一.采坑背景 在最大数据分析的过程中,redis是被当做热数据的缓存库使用的,在某一天中,redis数据库热数据无法插入,此时数据量大概在100万左右,很是纠结,为什么不能插入?程序的错误,不可能,没 ...
- SDM439平台出现部分机型SD卡不能识别mmc1: error -110 whilst initialising SD card【学习笔记】
SDM439平台出现部分机型SD卡不能识别mmc1: error -110 whilst initialising SD card 打印了如下的log: - ::>[ after ms - :: ...
- 文献阅读 | A single-cell molecular map of mouse gastrulation and early organogenesis
A single-cell molecular map of mouse gastrulation and early organogenesis Here we report the transcr ...
- libusb: android上集成libusb库
1. 下载libusb库. 可以到libusb库的官网(https://libusb.info/)或者是其官方的github仓库(https://github.com/libusb/libusb/re ...
- Java的方法类型
1.无参数无返回值的方法 package com.imooc.method; public class MethodDemo { public static void printStar() { Sy ...
- 几个支持 FreeSWITCH 的网络电话的安装与使用(linphone、MicroSIP、Sipdroid)
Ubuntu 安装 Linphone 安装命令 apt-get install linphone 安装完成后,在应用程序 --> 互联网 下就能看到 linphone,打开后注册 注意:linp ...
- [转]彻底解决deepin linux的无线网络问题
链接地址:https://bbs.deepin.org/forum.php?mod=viewthread&tid=153154
- [LeetCode] 128. Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- docker tag根据镜像id做标签,用于应用的回滚
示例 通过ID tag镜像 下面是tag一个id为0e5574283393的本地镜像到“fedora”存储库,tag名称version1.0: docker tag 0e5574283393 fedo ...
