cfanbo / cfanbo.github.io

1 stars 0 forks source link

如何查询mysql事务未提交 | 学习笔记 #182

Open cfanbo opened 1 year ago

cfanbo commented 1 year ago

https://blog.haohtml.com/archives/17364/

注意这篇文章并非死锁的,而是锁等待 到information_schema库下面,查看下面这个表: innodb_trx ## 当前运行的所有事务 innodb_locks ## 当前出现的锁 innodb_lock_waits ## 锁等待的对应关系 如果遇到死锁了,怎么解决呢?找到原始的锁ID,然后KILL掉一直持有的那个线程就可以了, 但是众多线程,可怎么找到引起死锁的线程ID呢? MySQL 发展到现在,已经非常强大了,这个问题很好解决。 直接从数据字典连查找。 我们来演示下。 线程A,我们用来锁定某些记录,假设这个线程一直没提交,或者忘掉提交了。 那么就一直存在,但是数据里面显示的只是SLEEP状态。 mysql> set @@autocommit=0; Query OK, 0 rows affected (0.00 sec) mysql> use test; Reading table information for completion oftableandcolumn names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +—————-+ | Tables_in_test | +—————-+ | demo_test | | t3 | +—————-+ 2 rowsinset (0.