Dùng profiling để kiểm tra resource usage của các statement trong session hiện tại. Bật profiling:
mysql> SET profiling = 1; Query OK, 0 rows affected (0.00 sec)
SHOW PROFILES liệt kê các statement gần đây kèm duration và query_id:
mysql> SHOW PROFILES; +----------+------------+--------------------------------------+ | Query_ID | Duration | Query | +----------+------------+--------------------------------------+ | 1 | 0.01602200 | drop table if exists t1 | | 2 | 0.57223450 | create table t1(id int) | | 3 | 0.00015425 | show profile for query1 | | 4 | 0.22945050 | create table e1(id int) | | 5 | 0.09977025 | insert into e1(id) values(3),(4),(5) | +----------+------------+--------------------------------------+ 5 rows in set (0.00 sec)
SHOW PROFILE FOR QUERY query_no chi tiết duration cho query cụ thể (ví dụ query_id=5):
mysql> SHOW PROFILE FOR QUERY 5; +------------------------------+--------------+ | Status | Duration | +------------------------------+--------------+ | starting | 0.000138 | | checking permissions | 0.000024 | | Opening tables | 0.000057 | | System lock | 0.035186 | | init | 0.000035 | | update | 0.021484 | | Waiting for query cache lock | 0.000021 | | update | 0.000005 | | end | 0.000024 | | query end | 0.042700 | | closing tables | 0.000017 | | freeing items | 0.000076 | | logging slow query | 0.000003 | | cleaning up | 0.000002 | +------------------------------+--------------+ 14 rows in set (0.00 sec)