In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "MySQL how to view slow query statements," interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "MySQL how to view slow query statements"!
To ensure database performance, we need to optimize slow query statements. This article shares Mysql database how to view slow query statements.
Mysql records slow query statements by default. Use the following command to view:
SHOW VARIABLES LIKE '%slow_query_log%';
After running, the effect is as follows:
slow_query_log value indicates whether to enable the function of recording slow query statements,
The value of slow_query_log_file represents the file name that the slow query statement will log.
Set the value of slow_query_log to 1 to enable this function, as follows:
SET GLOBAL slow_query_log=1;
The effect is as follows:
Query again:
It can be seen that the value of slow_query_log is ON, indicating that the function has been enabled.
So how long does the run-time statement get logged? So how slow is slow?
This time is recorded by long_query_time and can be checked with the following command:
SHOW VARIABLES LIKE 'long_query_time%';
The effect is as follows:
The default is 10 seconds, more than 10 seconds will be recorded.
Test it with the following statement:
SELECT sleep(11);
After 11 seconds, the following effect appears:
View files specified by slow_query_log_file:
You can see SELECT sleep(11); already logged.
We can set the value of long_query_time ourselves, for example, to 3 seconds:
SET GLOBAL long_query_time=3;
Operation effect:
Inquiry:
But still show 10, and did not show 3, do not worry, and then open a new query window to view:
You can see that it has been changed to 3.
At this time, check in the new query window:
SELECT sleep(4);
It will be recorded in the slow query log:
Note that the above settings for variables will expire after Mysql server restarts.
To make it permanent, modify the corresponding attribute values in the mysql configuration file.
At this point, I believe everyone has a deeper understanding of "MySQL how to view slow query statements," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.