当前位置:网站首页>1: Enable slow query log and find slow SQL
1: Enable slow query log and find slow SQL
2022-07-28 05:57:00 【Performer】
Why should I start slow query ?
Find the one to optimize sql, Slow query log is mysql A built-in function , You can record the execution of more than a specified time sql sentence .
How to start a slow query
1: Modify the configuration file my.conf,( Need to restart , The configuration is permanently valid , Will not be lost )
lookup my.cnf file
- linux The default path is generally /etc/my.cnf (windows To call down my.ini)
- Add the following to [mysqld] Next
service mysqld restart
# Open slow query log
slow_query_log=ON
# How long it takes will be recorded in the slow query log ( second )
long_query_time=0.5
# Slow query log storage mode , Can support at the same time File and table storage
log_output='FILE,TABLE'

- restart mysql The server , Input
SHOW VARIABLES LIKE 'slow_query_log'Check whether to turn on ,ON Already open
2: Set... Through global variables ( No need to restart , Once the restart , Configuration lost )
- Execute directly on the client The following command
SHOW VARIABLES LIKE 'slow_query_log'
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 0.001;
SET GLOBAL log_output = 'FILE,TABLE';


Find slow SQL
Query through table
- When slow_query_log contain TABLE when , Directly through sql Inquire about , without , It may be just opened , The timeout has not been found sql
SELECT * FROM mysql.slow_log

- Meaning of some fields
start_time Implement this sql The time of the statement
user_host user name And the host name
query_time Inquire about sql The time spent in the statement
lock_time Time to acquire lock
rows_sent Number of rows returned
rows_examined The number of rows queried by the server
db Query the database
sql_text Executive sql sentence
thread_id Thread of execution id
- For example, we can sort according to the time-consuming , Find the most time-consuming sql
SELECT
*
FROM
mysql.slow_log
ORDER BY query_time DESC

Query by file
- First you need to turn on FILE , Can pass
SHOW VARIABLES LIKE 'log_output'Check whether to turn on File store
- Query the path of log storage Can pass
SHOW VARIABLES LIKE 'slow_query_log_file'Inquire about


- have access to mysqldumpslow analysis :
for example : Find the most time-consuming front 10 statement
mysqldumpslow -s t -t 10 -a xxx-slow.log

- The specific parameters are as follows :
* mysqldumpslow --help
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
Parse and summarize the MySQL slow query log. Options are
--verbose verbose
--debug debug
--help write this text to standard output
-v Show more detailed information
-d debug
-s ORDER How to sort , Default at
al: Average lock time
ar: Average number of returned records
at: Average query time
c: Access count
l: Lock time
r: Back to the record
t: Query time
-r take -s In reverse order
-t NUM top n It means , Show the first few
-a Don't show the numbers as N, Display the string as 'S'
-n NUM abstract numbers with at least n digits within names
-g PATTERN You can write a regular , Only regular guilds show
-h HOSTNAME Slow query log to Host name -slow.log Format naming ,-h You can specify to read the slow query log of the specified host name , By default *, Read all slow query logs
-i NAME MySQL Server Instance name of ( If used mysql.server startup Script words )
-l Do not subtract the lock time from the total time
边栏推荐
猜你喜欢

微信公众号-授权登录

ArcGIS Engine开发资源

基于php学生学籍管理系统获取(php毕业设计)

ArcMap map map projection related operations

Sankey diagram drawing based on highcharts platform

(PHP graduation project) obtained based on PHP student homework submission management system

Model builder of ArcGIS

蓝桥代码 翻硬币(我这样写也通过了,官网测试是不是有问题)

cmd和npm基础命令

(php毕业设计)基于php小说网站管理系统获取
随机推荐
书籍-乌合之众
[interview question] anti shake and throttling
Books - mob
Prime_Series靶场从探测到提权
结果填空 奖券数目(dfs * 数学公式)
HDU-1284:钱币兑换问题 推理+动态规划(dp)
js-简单的发布订阅类
JS promise implementation logic
MySQL练习题50道+答案
Books - Templeton teaches you reverse
Zotero - a document management tool
抖音-视频步骤
(php毕业设计)基于php甘肃旅游网站管理系统获取
Time setting in curd component
Screenshot transferred to the background
cmd和npm基础命令
Books - mental models
mysql分页出现问题
数字藏品成文旅产业新热点
flex弹性盒子项目属性