十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章主要介紹“怎么獲取有性能問題的sql”,在日常操作中,相信很多人在怎么獲取有性能問題的sql問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么獲取有性能問題的sql”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)自2013年起,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元井陘礦做網(wǎng)站,已為上家服務(wù),為井陘礦各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792
用戶反饋:獲取存在性能問題的sql
慢查詢?nèi)罩荆韩@取存在性能問題的sql
實時獲取存在性能的sql
使用慢查詢?nèi)罩精@取有性能問題的sql
slow_query_log 啟動停止記錄慢查詢?nèi)罩?/p>
slow_query_log_file 指定慢查詢?nèi)罩镜拇鎯β窂揭约拔募?/p>
long_query_time 指定記錄慢查詢?nèi)罩緎ql執(zhí)行時間的閾值
log_queries_not_using_indexes 是否記錄未使用的索引的sql

1:用戶信息以及線程id
2:執(zhí)行查詢時間
3:鎖的時間
4、返回數(shù)據(jù)行數(shù)
5、掃描數(shù)據(jù)的行數(shù)
6、執(zhí)行sql時間
7、執(zhí)行的sql
常用慢查詢?nèi)罩痉治龉ぞ?nbsp; MySQLdumpslow




常用慢查詢分析工具 pt-query-digest
pt-query-digest \
--explain h=127.0.0.1, u=root,p=p@ssW0rd \ slow-mysql.log

實時查詢


查詢處理各個階段所消耗的時間
使用profile
1、set profiling = 1 ;
執(zhí)行查詢
啟動profile
這是一個session級的配置
2、show profiles;
查看每一個查詢所消耗的總時間的信息
mysql> show profiles;
+----------+------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| 1 | 0.00012525 | sel
select count(*) from temp_shop_user |
| 2 | 0.09744925 | select count(*) from temp_shop_user
3、show profiles for query N;
查詢的每個階段所消耗的時間
mysql> show profile for query 1 ;
+--------------------+----------+
| Status | Duration |
+--------------------+----------+
| starting | 2.5E-5 |
| freeing items | 9.6E-5 |
| logging slow query | 3E-6 |
| cleaning up | 2E-6 |
+--------------------+----------+
4 rows in set
4、查詢cpu信息
mysql> show profile cpu for query 3;
+----------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| starting | 3.5E-5 | 0 | 0 |
| checking permissions | 6E-6 | 0 | 0 |
| Opening tables | 1.3E-5 | 0 | 0 |
| System lock | 6E-6 | 0 | 0 |
| init | 8E-6 | 0 | 0 |
| optimizing | 3E-6 | 0 | 0 |
| statistics | 7E-6 | 0 | 0 |
| preparing | 4E-6 | 0 | 0 |
| executing | 2E-6 | 0 | 0 |
| Sending data | 0.0296 | 0.03125 | 0 |
| end | 1E-5 | 0 | 0 |
| query end | 3E-6 | 0 | 0 |
| closing tables | 8E-6 | 0 | 0 |
| freeing items | 0.000125 | 0 | 0 |
| logging slow query | 2E-6 | 0 | 0 |
| cleaning up | 3E-6 | 0 | 0 |
+----------------------+----------+----------+------------+
16 rows in set
5、performance_schema
5.6之后版本,建議啟用



1>進入performance_schema 庫
mysql> use performance_schema ;
Database changed
2>mysql> update setup_instruments set enabled ='YES' where name like 'stage%';
Query OK, 0 rows affected
Rows matched: 0 Changed: 0 Warnings: 0
3>啟動歷史記錄表
mysql> update setup_consumers set enabled ='YES' where name like 'events%';
Query OK, 0 rows affected
Rows matched: 6 Changed: 0 Warnings: 0
到此,關(guān)于“怎么獲取有性能問題的sql”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
網(wǎng)站名稱:怎么獲取有性能問題的sql
文章源于:http://m.jiaotiyi.com/article/jhgodj.html