我觉的这个问题不太容易,看了下文档,可以从information_schema.INNODB_TRX 表里得到当前系统所有在执行的事务的情况,包括是事务是否在等待锁,事务开始时间,当前的SQL语句.
表的列名如下:
其中 trx_state 的值为这4种状态其中之一. RUNNING, LOCK WAIT, ROLLING BACK or COMMITTING.
我觉的可以统计4个状态的事物数,可以大体上知道当前事物执行情况,如果有很多LOCK WAIT,那系统并发上可能存在问题。然后根据对应 SQL 语句(trx_query )进行分析。
引用文本
trx_id
trx_state
trx_started
trx_requested_lock_id
trx_wait_started
trx_weight
trx_mysql_thread_id
trx_query
trx_operation_state
trx_tables_in_use
trx_tables_locked
trx_lock_structs
trx_lock_memory_bytes
trx_rows_locked
trx_rows_modified
trx_concurrency_tickets
trx_isolation_level
trx_unique_checks
trx_foreign_key_checks
trx_last_foreign_key_error
trx_adaptive_hash_latched
trx_adaptive_hash_timeout
详细情况可以参考这里:
The INFORMATION_SCHEMA INNODB_TRX Tabl
http://dev.mysql.com/doc/refman/5.5/en/innodb-trx-table.html