欢迎来到天天文库
浏览记录
ID:32918325
大小:55.66 KB
页数:11页
时间:2019-02-17
《Linux数据库:MYSQL死锁相关查找》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Linux数据库:MYSQL死锁相关查找1如果遇到死锁了,怎么解决呢?找到原始的锁ID,然后KILL掉一直持有的那个线程就可以了,但是众多线程,可怎么找到引起死锁的线程ID呢?MySQL发展到现在,已经非常强大了,这个问题很好解决。直接从数据字典连查找。 我们来演示下。 线程A,我们用来锁定某些记录,假设这个线程一直没提交,或者忘掉提交了。那么就一直存在,但是数据里面显示的只是SLEEP状态。 mysql>set@@autocommit=0; QueryOK,0rowsaffected(0.00sec) mysql>usetest; Reading
2、tableinformationforcompletionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A Databasechanged mysql>showtables; +----------------+
3、Tables_in_test
4、 +----------------+
5、demo_test
6、
7、t3
8、 +----------------+ 2rowsinset(0.00sec) mysql>se
9、lect*fromt3; +----+--------+--------+------------+----+----+----+
10、id
11、fname
12、lname
13、birthday
14、c1
15、c2
16、c3
17、 +----+--------+--------+------------+----+----+----+
18、19
19、lily19
20、lucy19
21、2013-04-18
22、19
23、 0
24、 0
25、
26、20
27、lily20
28、lucy20
29、2013-03-13
30、20
31、 0
32、 0
33、 +----+--------+--------+------------+----
34、+----+----+ 2rowsinset(0.00sec) mysql>updatet3setbirthday='2022-02-23'whereid=19; QueryOK,1rowaffected(0.00sec) Rowsmatched:1 Changed:1 Warnings:0 mysql>selectconnection_id(); +-----------------+
35、connection_id()
36、 +-----------------+
37、 16
38、 +-----------------+
39、1rowinset(0.00sec) mysql> 线程B,我们用来进行普通的更新,但是遇到问题了,此时不知道是哪个线程把这行记录给锁定了? mysql>usetest; Readingtableinformationforcompletionoftableandcolumnnames Youcanturnoffthisfeaturetogetaquickerstartupwith-A Databasechanged mysql>select@@autocommit; +--------------+
40、@@autocommit
41、 +---
42、-----------+
43、 1
44、 +--------------+ 1rowinset(0.00sec) mysql>updatet3setbirthday='2018-01-03'whereid=19; ERROR1205(HY000):Lockwaittimeoutexceeded;tryrestartingtransaction mysql>selectconnection_id(); +-----------------+
45、connection_id()
46、 +-----------------+
47、
48、 17
49、 +-----------------+ 1rowinset(0.00sec) mysql>showprocesslist; +----+------+-----------+------+---------+------+-------+------------------+
50、Id
51、User
52、Host
53、db
54、Command
55、Time
56、State
57、Info
58、 +----+------+-----------+------+---------+------+-------+-------
59、-----------+
60、10
61、r
此文档下载收益归作者所有