执行此 SQL 查看元数据锁情况,上锁会话、SQL、锁类型能关联显示。SELECT
ps.*,
lock_summary.lock_summary
FROM
sys.processlist ps
INNER JOIN (
SELECT
owner_thread_id,
GROUP_CONCAT(
DISTINCT CONCAT(
mdl.LOCK_STATUS,
' ',
mdl.lock_type,
' on ',
IF(
mdl.object_type = 'USER LEVEL LOCK',
CONCAT(mdl.object_name, ' (user lock)'),
CONCAT(mdl.OBJECT_SCHEMA, '.', mdl.OBJECT_NAME)
)
)
ORDER BY
mdl.object_type ASC,
mdl.LOCK_STATUS ASC,
mdl.lock_type ASC SEPARATOR '\n'
) as lock_summary
FROM
performance_schema.metadata_locks mdl
GROUP BY
owner_thread_id
) lock_summary ON (ps.thd_id = lock_summary.owner_thread_id) \ G