您好,登錄后才能下訂單哦!
小編給大家分享一下如何使用Performance Schema查看Profiling,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
SHOW PROFILE可以用來MySQL執行語句時候所使用的資源(諸如IO,上下文切換,CPU,Memory等等),但是從MySQL 5.6.7開始此特性將被移除,而使用Performance Schema代替,如下:
MySQL 5.7.8, 可以通過setup_actors表來配置host, user, or account的信息被收集,如下:
#默認情況下setup_actors 的配置是允許監控和收集所有前臺線程的歷史事件信息
>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顯示的選項幾乎一樣,只是各項的值好像不太一致。
看完了這篇文章,相信你對“如何使用Performance Schema查看Profiling”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。