Mysql 事物阻塞

1、查看现有事物(锁),批量生成 kill 命令

select CONCAT('kill ', trx_mysql_thread_id, ';') as kill_command, a.*
from information_schema.innodb_trx as a 
-- where trx_query is null 

2、查看指定数据库的线程,及其对应的事物(锁),批量生成 kill 命令

select CONCAT('kill ', trx_mysql_thread_id, ';') as kill_command, a.*, b.*
from information_schema.processlist as a 
left join information_schema.innodb_trx as b
-- join information_schema.innodb_trx as b
on a.id = b.trx_mysql_thread_id 

where a.db = 'my_db'
-- and b.trx_query is null

3、查看事务超时时间

SHOW VARIABLES LIKE 'innodb_lock_wait_timeout';

lock_wait_timeout 是一个服务器级别的参数,它用于设置所有连接在等待行级锁或表级锁时可以等待的最大时间。当连接等待的时间超过了 lock_wait_timeout 的值时,MySQL 将抛出一个错误,并终止连接。默认值为 31536000 秒(即一年)。

innodb_lock_wait_timeout 是一个存储引擎级别的参数,它仅用于设置使用 InnoDB 存储引擎的连接在等待行级锁或表级锁时可以等待的最大时间。当连接等待的时间超过了 innodb_lock_wait_timeout 的值时,InnoDB 将抛出一个错误,并终止连接。默认值为 50 秒。

建议将 innodb_lock_wait_timeout 的值设置得比较小,因为这可以有效避免因等待锁而导致的超时问题。但是,也要注意不要设置得过小,以免在高并发的情况下出现频繁的超时错误。

相关推荐

  1. Mysql 事物阻塞

    2024-04-11 10:10:04       43 阅读
  2. Mysql数据库——阻塞语句查询与分析

    2024-04-11 10:10:04       44 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-11 10:10:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-11 10:10:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-11 10:10:04       87 阅读
  4. Python语言-面向对象

    2024-04-11 10:10:04       96 阅读

热门阅读

  1. PHP 图片裁剪类封装

    2024-04-11 10:10:04       32 阅读
  2. 2192. 有向无环图中一个节点的所有祖先

    2024-04-11 10:10:04       39 阅读
  3. Visual Studio 2022 快速注释代码

    2024-04-11 10:10:04       40 阅读
  4. 使用Django开发爬虫系统

    2024-04-11 10:10:04       39 阅读
  5. JJJ:netdev_run_todo

    2024-04-11 10:10:04       31 阅读
  6. 01背包问题 小明的背包

    2024-04-11 10:10:04       37 阅读
  7. 常见分类算法

    2024-04-11 10:10:04       38 阅读