mysql死锁
2016-03-23 14:47
465 查看
mysql死锁:
1、查询是否锁表
show OPEN TABLES where In_use > 0;
2、查询进程
show processlist
查询到相对应的进程===然后 kill id
#查看正在锁的事务#
SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX
#查看等待锁的事务#
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
如何查看MySQL数据库的死锁信息
mysql> show engine innodb status;
找到LATEST DETECTED DEADLOCK这一行
mysql> show engine innodb status;
LATEST DETECTED DEADLOCK
------------------------
160323 16:01:19
*** (1) TRANSACTION:
TRANSACTION 26CD, ACTIVE 61 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1248, 2 row lock(s), undo log entries 1
MySQL thread id 10218, OS thread handle 0x7f0ae41fa700, query id 4002030 123.56.118.135 root Updating
update diaocha_user set sex='b' where id=74
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 414 n bits 168 index `PRIMARY` of table `app`.`diaocha_user` trx id 26CD lock_mode X locks rec but not gap waiting
Record lock, heap no 100 PHYSICAL RECORD: n_fields 18; compact format; info bits 0
0: len 4; hex 8000004a; asc J;;
1: len 6; hex 0000000026ce; asc & ;;
2: len 7; hex 35000002b20f74; asc 5 t;;
3: len 1; hex 62; asc b;;
4: SQL NULL;
5: SQL NULL;
6: SQL NULL;
7: SQL NULL;
8: SQL NULL;
9: SQL NULL;
10: SQL NULL;
11: SQL NULL;
12: len 0; hex ; asc ;;
13: len 0; hex ; asc ;;
14: len 0; hex ; asc ;;
15: SQL NULL;
16: SQL NULL;
17: SQL NULL;
*** (2) TRANSACTION:
TRANSACTION 26CE, ACTIVE 51 sec starting index read
mysql tables in use 1, locked 1
3 lock struct(s), heap size 1248, 2 row lock(s), undo log entries 1
MySQL thread id 10219, OS thread handle 0x7f0ae412a700, query id 4002052 123.56.118.135 root Updating
<span style="color:#ff0000;">update diaocha_user set sex='b' where id=73</span>
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 0 page no 414 n bits 168 index `PRIMARY` of table `app`.`diaocha_user` trx id 26CE lock_mode X locks rec but not gap
Record lock, heap no 100 PHYSICAL RECORD: n_fields 18; compact format; info bits 0
0: len 4; hex 8000004a; asc J;;
1: len 6; hex 0000000026ce; asc & ;;
2: len 7; hex 35000002b20f74; asc 5 t;;
3: len 1; hex 62; asc b;;
4: SQL NULL;
5: SQL NULL;
6: SQL NULL;
7: SQL NULL;
8: SQL NULL;
9: SQL NULL;
10: SQL NULL;
11: SQL NULL;
12: len 0; hex ; asc ;;
13: len 0; hex ; asc ;;
14: len 0; hex ; asc ;;
15: SQL NULL;
16: SQL NULL;
17: SQL NULL;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 414 n bits 168 index `PRIMARY` of table `app`.`diaocha_user` trx id 26CE lock_mode X locks rec but not gap waiting
Record lock, heap no 99 PHYSICAL RECORD: n_fields 18; compact format; info bits 0
0: len 4; hex 80000049; asc I;;
1: len 6; hex 0000000026cd; asc & ;;
2: len 7; hex 340000023e06bc; asc 4 > ;;
3: len 1; hex 62; asc b;;
4: SQL NULL;
5: SQL NULL;
6: SQL NULL;
7: SQL NULL;
8: SQL NULL;
9: SQL NULL;
10: SQL NULL;
11: SQL NULL;
12: len 0; hex ; asc ;;
13: len 0; hex ; asc ;;
14: len 0; hex ; asc ;;
15: SQL NULL;
16: SQL NULL;
17: SQL NULL;
*** WE ROLL BACK TRANSACTION (2)
相同表,
a命令行
b命令行
a命令行执行更新id=74
b命令行执行更新id=73
然后
b命令行执行更新id=74
a命令行执行更新id=73
死锁出来了。。。。。
死锁生成原因:
http://www.cnblogs.com/LBSer/p/5183300.htm
1、查询是否锁表
show OPEN TABLES where In_use > 0;
2、查询进程
show processlist
查询到相对应的进程===然后 kill id
#查看正在锁的事务#
SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX
#查看等待锁的事务#
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
如何查看MySQL数据库的死锁信息
mysql> show engine innodb status;
找到LATEST DETECTED DEADLOCK这一行
mysql> show engine innodb status;
LATEST DETECTED DEADLOCK
------------------------
160323 16:01:19
*** (1) TRANSACTION:
TRANSACTION 26CD, ACTIVE 61 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1248, 2 row lock(s), undo log entries 1
MySQL thread id 10218, OS thread handle 0x7f0ae41fa700, query id 4002030 123.56.118.135 root Updating
update diaocha_user set sex='b' where id=74
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 414 n bits 168 index `PRIMARY` of table `app`.`diaocha_user` trx id 26CD lock_mode X locks rec but not gap waiting
Record lock, heap no 100 PHYSICAL RECORD: n_fields 18; compact format; info bits 0
0: len 4; hex 8000004a; asc J;;
1: len 6; hex 0000000026ce; asc & ;;
2: len 7; hex 35000002b20f74; asc 5 t;;
3: len 1; hex 62; asc b;;
4: SQL NULL;
5: SQL NULL;
6: SQL NULL;
7: SQL NULL;
8: SQL NULL;
9: SQL NULL;
10: SQL NULL;
11: SQL NULL;
12: len 0; hex ; asc ;;
13: len 0; hex ; asc ;;
14: len 0; hex ; asc ;;
15: SQL NULL;
16: SQL NULL;
17: SQL NULL;
*** (2) TRANSACTION:
TRANSACTION 26CE, ACTIVE 51 sec starting index read
mysql tables in use 1, locked 1
3 lock struct(s), heap size 1248, 2 row lock(s), undo log entries 1
MySQL thread id 10219, OS thread handle 0x7f0ae412a700, query id 4002052 123.56.118.135 root Updating
<span style="color:#ff0000;">update diaocha_user set sex='b' where id=73</span>
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 0 page no 414 n bits 168 index `PRIMARY` of table `app`.`diaocha_user` trx id 26CE lock_mode X locks rec but not gap
Record lock, heap no 100 PHYSICAL RECORD: n_fields 18; compact format; info bits 0
0: len 4; hex 8000004a; asc J;;
1: len 6; hex 0000000026ce; asc & ;;
2: len 7; hex 35000002b20f74; asc 5 t;;
3: len 1; hex 62; asc b;;
4: SQL NULL;
5: SQL NULL;
6: SQL NULL;
7: SQL NULL;
8: SQL NULL;
9: SQL NULL;
10: SQL NULL;
11: SQL NULL;
12: len 0; hex ; asc ;;
13: len 0; hex ; asc ;;
14: len 0; hex ; asc ;;
15: SQL NULL;
16: SQL NULL;
17: SQL NULL;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 414 n bits 168 index `PRIMARY` of table `app`.`diaocha_user` trx id 26CE lock_mode X locks rec but not gap waiting
Record lock, heap no 99 PHYSICAL RECORD: n_fields 18; compact format; info bits 0
0: len 4; hex 80000049; asc I;;
1: len 6; hex 0000000026cd; asc & ;;
2: len 7; hex 340000023e06bc; asc 4 > ;;
3: len 1; hex 62; asc b;;
4: SQL NULL;
5: SQL NULL;
6: SQL NULL;
7: SQL NULL;
8: SQL NULL;
9: SQL NULL;
10: SQL NULL;
11: SQL NULL;
12: len 0; hex ; asc ;;
13: len 0; hex ; asc ;;
14: len 0; hex ; asc ;;
15: SQL NULL;
16: SQL NULL;
17: SQL NULL;
*** WE ROLL BACK TRANSACTION (2)
相同表,
a命令行
mysql> set autocommit=off ; Query OK, 0 rows affected mysql> update diaocha_user set sex='b' where id=74; Database changed Rows matched: 1 Changed: 1 Warnings: 0 mysql> update diaocha_user set sex='b' where id=73; Database changed Rows matched: 1 Changed: 0 Warnings: 0 mysql>
b命令行
mysql> set autocommit=off; Query OK, 0 rows affected mysql> update diaocha_user set sex='c' where id=73; Database changed Rows matched: 1 Changed: 1 Warnings: 0 mysql> update diaocha_user set sex='c' where id=74; 1213 - Deadlock found when trying to get lock; try restarting transaction mysql>
a命令行执行更新id=74
b命令行执行更新id=73
然后
b命令行执行更新id=74
a命令行执行更新id=73
死锁出来了。。。。。
死锁生成原因:
http://www.cnblogs.com/LBSer/p/5183300.htm
相关文章推荐
- mysql 按照姓氏排序
- MySQL数据库的备份与还原
- mysql集群
- 浅谈MySQL数据库查询优化
- mysql修改max_allowed_packet
- ubuntu的mysql卸载与安装
- mysql求某个列的前10条记录的总和
- 理解MySQL存储过程和函数
- 连接MYSQL的时候报错(找不到请求的.net framework data provider。可能没有安装
- sql按照in中的顺序进行排序 mysql
- mysql数据库设置远程连接权限
- mysql 将多行转换一行
- MySQL数据类型--二进制类型
- MySQL复制过滤参数解释
- mysql-5.5多实例配置
- MySQL数据库binlog日志管理
- MySql同时更新多条记录的方法
- MySQL显示命令
- mysql 命令符操作登陆 展开 查看对象 查看数据表名称 数据表结构 插入
- MySql游标的使用