How to View Deadlock Logs for MySQL Databases

How to view the deadlock log of MySQL database

1. Log in to MySQL using a terminal or command prompt and enter the command : mysql -h xxxx.xxx.xxx -P 3306 -u username -p
Explanation: xxxx.xxx.xxx is the database IP address , username is the database username. After entering the command, you will be asked to enter the password corresponding to the username, and you can log in


. 2. How to view the deadlock information of the MySQL database
Enter the command under the MySQL client:
show engine innodb status \G;



3 . How to locate the deadlock information of the MySQL database
Find the content of the "LATEST DETECTED DEADLOCK" section in the printed information, see the red line in the figure


4. How to analyze the log and locate the cause of the deadlock,
see the figure in 3, the purple underlined part of the

analysis:
Transaction 1, waiting for
RECORD LOCKS space id 553 page no 376 n bits 368 index `index_user_id` of table `tbj`.`score_user`, X lock at this position
Transaction 2, holding
RECORD LOCKS space id 553 page no 376 n bits 368 index `index_user_id` of table `tbj`.`score_user` S lock in this place
Transaction 2, waiting for X lock in this place

In theory, this transaction 2 can be committed, no deadlock, but this transaction log only prints the last part of the deadlock, information, the implicit condition here is that transaction 1 also holds
RECORD LOCKS space id 553 page no 376 n bits 368 index `index_user_id` of table `tbj`.`score_user` is an S lock in this place. In this way, transaction 2 cannot add X lock, and transaction 1 cannot add X lock, resulting in a deadlock.


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

Welcome to my public


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326489787&siteId=291194637