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