Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to open Mysql slow query log

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to open the Mysql slow query log", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to open the Mysql slow query log.

Check whether slow query is enabled on the current server:

1. Quick way to run the sql statement show VARIABLES like "% slow%"

2. Go directly to my.conf to check.

Configuration in my.conf (add under [mysqld])

[mysqld]

Log-slow-queries = / data/mysql/10-9-138-42-slow.log

Long_query_time = 1 # unit is second

Log-queries-not-using-indexes

Use the SQL statement to modify: cannot be modified according to the items in my.conf. Modified through "show VARIABLES like" slow% ""

Statement, run the following sql:

Set global log_slow_queries = ON

Set global slow_query_log = ON

Set global long_query_time=0.1; # set sql statements greater than 0.1s to record

After that, restart the database of Mysql: start it with service: service mysqld start

Information format of slow query log files:

Select sleep (3); this is the key message, indicating that the statement was executed at that time

Set the relationship between millisecond level and mysql version

Many online materials show that in versions prior to 5.21, the long_query_time in my.conf can only be set to a minimum of 1 (that is, at least 1 second). I bumped into myself and found that I could achieve it in other ways.

I didn't try "long_query_time = 0.1" because the database server was running. A reboot is required. So I didn't try. I implement the slow log query record through the global variable setting.

Millisecond level recording can be achieved by setting global variables:

Set global long_query_time = 0.01,

The mysql version on my server is 5.5.53

I've tried to work this way.

How to test whether your query

Will be recorded?

Run statement

Select sleep (3)

I deliberately set a 3-second delay, and then this statement is recorded in the log file as expected (because the previous setting was more than 0.1 seconds).

At this point, I believe you have a deeper understanding of "how to open the Mysql slow query log". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report