如何查看MySQL数据库的死锁日志

如何查看MySQL数据库的死锁日志

1. 使用终端或命令提示符登录到MySQL,输入命令:mysql -h xxxx.xxx.xxx -P 3306 -u username -p
解释:xxxx.xxx.xxx是数据库IP地址,username是数据库用户名,输入命令后,会让你输入username对应的密码,就可以登录了


2. 如何查看MySQL数据库的死锁信息
在MySQL客户端下输入命令:
show engine innodb status \G;



3. 如何定位MySQL数据库的死锁信息
在打印出来的信息中找到“LATEST DETECTED DEADLOCK”一节内容,看图中红线


4. 如何分析日志,定位死锁原因
看3里面的图,紫色划线部分

分析:
事务1,等待
RECORD LOCKS space id 553 page no 376 n bits 368 index `index_user_id` of table `tbj`.`score_user`,这个位置的X锁
事务2,持有
RECORD LOCKS space id 553 page no 376 n bits 368 index `index_user_id` of table `tbj`.`score_user`这个地方的S锁
事务2,等待这个地方的X锁

理论上这个事务2是可以提交的不会,死锁,但是这个事务日志只打印最后一部分死锁,信息,这里面隐含的条件是,事务1也持有
RECORD LOCKS space id 553 page no 376 n bits 368 index `index_user_id` of table `tbj`.`score_user`这个地方的S锁,这样,事务2不能加X锁,同时事务1也不能加X锁,产生死锁。


参考:
http://blog.csdn.net/hw_libo/article/details/39080809
http://jingyan.baidu.com/article/09ea3ede0745eac0aede39a3.html

欢迎大家关注我的公众号


猜你喜欢

转载自825635381.iteye.com/blog/2339503
今日推荐