MySQL Query Profiler, 可以查询到此 SQL 语句会执行多少, 并看出 CPU/Memory 使用
量, 执行过程 System lock, Table lock 花多少时间等等.
mysql> show variables like 'profiling%';
+------------------------+-------+
| Variable_name
+------------------------+-------+
| profiling
| profiling_history_size | 15
+------------------------+-------+
开启此功能
mysql>set profiling=1;
mysql> show variables like 'profiling%';
# 此命令会让mysql在 information_schema 的 database 建立一個 PROFILING 的
table 来记录.
+------------------------+-------+
| Variable_name
+------------------------+-------+
| profiling
| profiling_history_size | 15
+------------------------+-------+
profiling_history_size记录多少次查询
mysql> show profiles;
+----------+------------+------------------------------------+
| Query_ID | Duration
+----------+------------+------------------------------------+
|
|
|
|
|
|
|
mysql> show profile for query 6;
+--------------------------------+----------+
| Status
+--------------------------------+----------+
| (initialization)
| checking query cache for query | 0.000042 |
| Opening tables
| System lock
| Table lock
| init
| optimizing
| statistics
| preparing
| executing
| Sending data
| end
| query end
| storing result in query cache | 0.000002 |
| freeing items
| closing tables
| logging slow query
+--------------------------------+----------+
17 rows in set (0.00 sec)
mysql> show profile cpu for query 6;
+--------------------------------+----------+----------+------------+
| Status
+--------------------------------+----------+----------+------------+
| (initialization)
| checking query cache for query | 0.000042 | 0.001
| Opening tables
| System lock
| Table lock
| init
| optimizing
| statistics
| preparing
| executing
| Sending data
| end
| query end
| storing result in query cache | 0.000002 | 0
| freeing items
| closing tables
| logging slow query
+--------------------------------+----------+----------+------------+
17 rows in set (0.00 sec)
context switches
with the name and line number of the file in which the function occurs
查询时间跟cpu的使用
mysql> select min(seq) seq,state,count(*) numb_ops,
关闭此功能
mysql> set profiling=0;
mysql> show variables like 'profiling%';
+------------------------+-------+
| Variable_name
+------------------------+-------+
| profiling
| profiling_history_size | 15
+------------------------+-------+
5902



被折叠的 条评论
为什么被折叠?



