mysql 什么情况下会报lock wait timeout exceeded;try restarting transaction
发布网友
发布时间:2022-04-09 16:06
我来回答
共2个回答
懂视网
时间:2022-04-09 20:27
相关等待锁的线程以及谁持有锁可以在错误日志中找到
#以下是innodb存储引擎中锁等待以及哪个线程持有锁的查找sql
SELECT r.trx_id AS waiting_trx_id, r.trx_mysql_thread_id AS waiting_thread, TIMESTAMPDIFF(SECOND, r.trx_wait_started, CURRENT_TIMESTAMP) AS wait_time, r.trx_query AS waiting_query, l.lock_table AS waiting_table_lock, b.trx_id AS blocking_trx_id, b.trx_mysql_thread_id AS blocking_thread, SUBSTRING(p.host,1, INSTR(p.host, ‘:‘) -1) AS blocking_host, SUBSTRING(p.host, INSTR(p.host, ‘:‘) +1) AS block_port, IF(p.command="Sleep",p.time,0) AS idle_in_trx, b.trx_query AS blcoking_query
FROM information_schema.innodb_lock_waits AS w
INNER JOIN information_schema.innodb_trx AS b ON b.trx_id=w.blocking_trx_id
INNER JOIN information_schema.innodb_trx AS r ON r.trx_id = w.requesting_trx_id
INNER JOIN information_schema.innodb_locks AS l ON w.requested_lock_id = l.lock_id
LEFT JOIN information_schema.processlist AS p ON p.id = b.trx_mysql_thread_id
ORDER BY wait_time DESC;
#下面查询显示存储引擎层有多少查询被哪些线程阻塞
SELECT CONCAT(‘thread ‘, b.trx_mysql_thread_id, ‘ from ‘,p.host) AS who_blocks, IF (p.command = "Sleep",p.time, 0) AS idle_in_trx, MAX(TIMESTAMPDIFF(SECOND,r.trx_wait_started, NOW())) AS max_wait_time, COUNT(*) AS num_waiters
FROM information_schema.innodb_lock_waits AS w
INNER JOIN information_schema.innodb_trx AS b ON b.trx_id = w.blocking_trx_id
INNER JOIN information_schema.innodb_trx AS r ON r.trx_id = w.requesting_trx_id
LEFT JOIN information_schema.processlist AS p ON p.id = b.trx_mysql_thread_id
GROUP BY who_blocks
ORDER BY num_waiters DESC;
MySQL找出锁等待
标签:blocking min now() 存储引擎 服务 who 服务器 instr query
热心网友
时间:2022-04-09 17:35
1、锁等待超时。是当前事务在等待其它事务释放锁资源造成的。可以找出锁资源竞争的表和语句,优化你的SQL,创建索引等,如果还是不行,可以适当减少并发线程数。
2、你的事务在等待给某个表加锁时超时了,估计是表正被另的进程锁住一直没有释放。
可以用 SHOW INNODB STATUS/G; 看一下锁的情况。
3、搜索解决 之道
在管理 节点的[ndbd default]
区加:
TransactionDeadLockDetectionTimeOut=10000(设置 为10秒)默认是1200(1.2秒)
4、InnoDB会自动的检测死锁