Home > Database > Mysql Tutorial > What does mysql's slow query log record?

What does mysql's slow query log record?

WBOY
Release: 2022-05-19 16:34:16
Original
2659 people have browsed it

In mysql, the slow query log records statements whose response time exceeds the threshold; the response time threshold is the value whose running time exceeds "long_query_time". The default value of this value is 10, which is the slow query log record. SQL statements that take more than ten seconds to run. The slow query log writes log records to log files and database tables.

What does mysql's slow query log record?

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

What does mysql’s slow query log record?

MySQL’s slow query, the full name is slow query log, is a log record provided by MySQL, used to record when the response time in MySQL exceeds the threshold value statement.

In specific environments, SQL statements whose running time exceeds the long_query_time value will be recorded in the slow query log.

The default value of long_query_time is 10, which means that statements running for more than 10 seconds are recorded.

By default, the MySQL database does not start the slow query log, and you need to set this parameter manually.

Of course, if it is not required for tuning, it is generally not recommended to enable this parameter, because enabling the slow query log will have a more or less certain performance impact.

Slow query log supports writing log records to log files and database tables.

Parameter description

  • slow_query_log: Whether to enable slow query log, 1 means on, 0 means off.

  • log-slow-queries: Old version (version below 5.6) MySQL database slow query log storage path. You can not set this parameter, and the system will default to a default file host_name-slow.log

  • slow-query-log-file: New version (5.6 and above) MySQL database Slow query log storage path. You can not set this parameter, the system will default to a default file host_name-slow.log

  • long_query_time: slow query threshold, when the query time is longer than the set threshold, Keep a log.

  • log_queries_not_using_indexes: Queries that do not use indexes are also logged to the slow query log (optional).

  • log_output: Log storage method. log_output='FILE' means to save the log to a file, and the default value is 'FILE'. log_output='TABLE' means to store the log in the database.

Extended knowledge:

1. Check the status of the slow log function. The slow log function is turned off by default show variables like '%slow_query_log% ';

OFF indicates that the slow log function is turned off. The slow log records are stored in the DESKTOP-2331B4V-slow.log file. DESKTOP is the name of my computer.

2. Turn on the slow log function set global slow_query_log=1;

Then query the slow log status

The status is ON, which means the slow log function is turned on.

3. Check the default long_query_time time

long_query_time is 10 seconds, which means that SQ statements that exceed 10 seconds will be recorded in the slow log.

4. Set long_query_time, the default 10 seconds is too long set global long_query_time=3;

Reopen a session, if it is a window system, just punch in a cmd again (note If you still query the long_query_time duration in the session where long_query_time is set, it will still be the default 10 seconds, so you need to restart a session) and query the long_query_time duration again

Recommended learning: mysql video tutorial

The above is the detailed content of What does mysql's slow query log record?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template