当前位置:网站首页>MySQL tuning -- 02 -- slow query log

MySQL tuning -- 02 -- slow query log

2022-06-25 05:49:00 High high for loop

Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right


Slow query log

 Insert picture description here

1. Enable the slow query log parameter

1.1 Turn on slow_query_log

 Insert picture description here
 Insert picture description here

1.2 modify long_query_time threshold

 Insert picture description here
 Insert picture description here
 Insert picture description here

2. View the number of slow queries

 Insert picture description here
 Insert picture description here
 Insert picture description here

3. Slow query log analysis tool :mysqldumpslow

 Insert picture description here

 Insert picture description here
 Insert picture description here

3.1 give an example

 Insert picture description here

 Insert picture description here
 Insert picture description here

3.2 Common references for work :

 Insert picture description here

4. Turn off slow query log

MySQL There are two ways for the server to stop the slow query log function :

The way 1: Permanent way

 Insert picture description here

The way 2: Temporary way

 Insert picture description here

5. Delete slow query log

 Insert picture description here

Slow query case

Table structure

CREATE TABLE `person_info_large` (  
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,  
    `account` VARCHAR (10),   
    `name` VARCHAR (20),  
    `area` VARCHAR (20),  
    `title` VARCHAR (20), 
    `motto` VARCHAR (50),
    PRIMARY KEY (`id`),  
    UNIQUE(`account`),
    KEY `index_area_title`(`area`,`title`) 
) ENGINE = INNODB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8  

run

  • The data here is 200W strip . Note the table structure , Just remember which fields have indexes , The following analysis will focus on this table .
     Insert picture description here
    This 3.36s Not the actual execution time , The actual execution time has to be slow. Check the log Query_time Parameters

Slow query log files

 Insert picture description here

You can see Query_time: 6.337729s, More than the 1s, So it will be recorded

  • Be careful : Some slow queries are executing , As a result, the database has been overloaded , However, due to the slow speed, the query has not been executed yet , Therefore, the slow query log cannot see any statements , You can use show processlist Command to view the slow query being executed .show processlist Show which threads are running , If there is PROCESS jurisdiction , You can see all threads . otherwise , You can only see the current session thread .

Parameter description

  • Time: The time when the slow query occurred
  • Query_time: Query time
  • Lock_time: Time waiting to lock the watch
  • Rows_sent: The number of rows returned by the statement
  • Rows_exanined: Number of rows read from the storage engine during statement execution

 Insert picture description here

concerns

 Insert picture description here
 Insert picture description here

Focus on : Rows_exanined Number of scanning lines / Rows_sent Returns the number of rows

原网站

版权声明
本文为[High high for loop]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202201256425259.html