《MySQL 慢查詢日志》要點:
本文介紹了MySQL 慢查詢日志,希望對您有用。如果有疑問,可以聯系我們。
MySQL有一種日志,叫做慢查詢日志,主要就是用來記錄一些耗時的查詢操
作.通過這個日志我們就可以分析出哪些的操作是影響性能的,我們需要對其
進行一些優化措施.
查看開啟狀態
上面的截圖是我在 windows 下安裝的 MySQL5.7 版本,我們可以發現,這個版本是開啟了慢查詢的.我在 CentOS6.9 下采用 yum 的方式安裝的 MySQL5.7 默認沒有開啟慢查詢日志.不管默認有沒有給我們開啟,我們是需要了解慢查詢日志是如何開啟的,開啟的方式也非常簡單.找到 MySQL 的配置文件,Windows 下是 my.ini,Linux 下的是 my.cnf.進行如下配置就可以了.
slow-query-log=1
slow_query_log_file="mysql-slow.log"
long_query_time=10
第一行是指定開啟慢查詢日志
第二行是指定慢查詢日志的路徑
第三行是指定查詢時間大于多少的才進行記錄,但是是毫秒,也就是操作大于 10ms 的操作都會被記錄.
配置完畢之后要重啟 MySQL 生效.
下面來看看慢查詢日志的內容
C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe, Version: 5.7.16-log (MySQL
Community Server (GPL)). started with:
TCP Port: 3306, Named Pipe: (null)
TimeId CommandArgument
#Time: 2017-07-07T06:35:46.995201Z
#User@Host: root[root] @ localhost [::1] Id:10
#Query_time: 12.522116 Lock_time: 0.000501 Rows_sent: 0 Rows_examined: 483968 use test;
SET timestamp=1499409346;
insert into test (id,name) (select uuid() id,name from test);
#Time: 2017-07-07T06:36:15.258316Z
#User@Host: root[root] @ localhost [::1] Id:10
#Query_time: 24.543267 Lock_time: 0.000501 Rows_sent: 0 Rows_examined: 967936 SET timestamp=1499409375;
insert into test (id,name) (select uuid() id,name from test);
#Time: 2017-07-07T06:37:15.021922Z
#User@Host: root[root] @ localhost [::1] Id:10
#Query_time: 56.283040 Lock_time: 0.000499 Rows_sent: 0 Rows_examined: 1935872 SET timestamp=1499409435;
insert into test (id,name) (select uuid() id,name from test);
#Time: 2017-07-07T06:40:07.866659Z
#User@Host: root[root] @ localhost [::1] Id:10
#Query_time: 133.866927 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 3871744 SET timestamp=1499409607;
insert into test (id,name) (select uuid() id,name from test);
我們可以看到在 2017-07-07 日,有多個慢查詢產生.單獨抽取一組,如下
#Time: 2017-07-07T06:35:46.995201Z
#User@Host: root[root] @ localhost [::1] Id:10
#Query_time: 12.522116 Lock_time: 0.000501 Rows_sent: 0 Rows_examined: 483968 use test;
SET timestamp=1499409346;
insert into test (id,name) (select uuid() id,name from test);
Query_time 表示的是耗時時間
下面是一些操作,這的主要操作就是一個 insert
這就是慢查詢日志.
查看更多內容:http://www.roncoo.com/article/index
維易PHP培訓學院每天發布《MySQL 慢查詢日志》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/7085.html