SHOW PROFILE可以用来MySQL执行语句时候所使用的资源(诸如IO,上下文切换,CPU,Memory等等),但是从MySQL 5.6.7开始此特性将被移除,而使用Performance Schema代替,如下:
>SELECT * FROM performance_schema.setup_actors;
+------+------+------+---------+---------+
| HOST | USER | ROLE | ENABLED | HISTORY |
+------+------+------+---------+---------+
| % | % | % | YES | YES |
+------+------+------+---------+---------+
1 row in set (0.03 sec)
mysql> UPDATE performance_schema.setup_actors SET ENABLED = 'NO', HISTORY = 'NO'
-> WHERE HOST = '%' AND USER = '%';
mysql> INSERT INTO performance_schema.setup_actors (HOST,USER,ROLE,ENABLED,HISTORY)
-> VALUES('localhost','test_user','%','YES','YES');
#修改后的配置如下:
mysql> SELECT * FROM performance_schema.setup_actors;
+-----------+-----------+------+---------+---------+
| HOST | USER | ROLE | ENABLED | HISTORY |
+-----------+-----------+------+---------+---------+
| % | % | % | NO | NO |
| localhost | test_user | % | YES | YES |
+-----------+-----------+------+---------+---------+
#只监控和收集test_user@localhost用户相关的事件信息
mysql> UPDATE performance_schema.setup_instruments SET ENABLED = 'YES', TIMED = 'YES' |
mysql> UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' |
mysql >set profiling=1; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql >show warnings; #此处,也可以看到此特性将被移除的警告 +---------+------+----------------------------------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------------------------------+ | Warning | 1287 | '@@profiling' is deprecated and will be removed in a future release. | +---------+------+----------------------------------------------------------------------+ 1 row in set (0.00 sec) |
mysql >select * from t; +----+------+ | 9 | 15 | | 10 | 15 | | 2 | 20 | | 3 | 20 | | 8 | 25 | +----+------+ 5 rows in set (0.00 sec)5 rows in set (0.00 sec) |
mysql>show profiles; |
mysql>show profile for query 2; |
注:此处只为了说明问题,可能还查询到很多其他的SQL,但是我们自己知道我们执行的SQL是哪条,其他的SQL此处都被省略了
mysql>SELECT event_name AS Stage, TRUNCATE(TIMER_WAIT/1000000000000,6) AS Duration >FROM performance_schema.events_stages_history_long WHERE NESTING_EVENT_ID=79; |
如上,实现了通过Performance Schema来查询profileing相关信息,最终能看到的选项跟show profile显示的选项几乎一样,只是各项的值好像不太一致。
综上,MySQL 5.6.7开始推荐使用Performance Schema查看profile,而不是show profiles。Performance Schema查看profiling的基本步骤可参考本文。
参考:
http://dev.mysql.com/doc/refman/5.7/en/performance-schema-query-profiling.html