9. Slow query log

1. MySQL log type The
log is used to record the operation of the database and various operations performed by the user on the database. When the database fails, you can analyze and solve the problem based on the log to restore the database.

Log description
Redo log Redo log is a physical format log, which records the modification information of physical data pages, and writes them sequentially to redo log file
Rollback log The rollback log is a log in a logical format. When the undo is executed, it only logically restores the data to the state before the transaction, instead of operating on the physical page. This is different from the redo log.
Binary log Binary log is a logical format log that records operations in the database in the form of a binary file, but does not record query statements
Error log The error log records the start and stop of mysqld and related information about errors that occur during the operation of the server
Slow query log Slow query log records query statements that take too long to execute and do not use indexes
General query log Every query or command received by the server is recorded. The general log will record it regardless of whether the query or command is correct or even contains syntax errors.
Relay log Relay log is similar to binary; it can be used in replication architecture to keep the data of slave server and master server consistent

2. Slow query log The
slow query log is used to record statements in the MySQL database whose response time exceeds the specified threshold. The slow query log is usually called the slow log because it is not only for select statements, such as insert, update, delete and other statements. As long as the response time exceeds the set threshold, it will be recorded in the slow query log.

parameter description
slow_query_log Whether to open the slow query log, 1 means open, 0 means closed
slow_query_log_file Slow query log storage path, optional. Note: For versions before MySQL 5.6, the parameter name is log-slow-queries
long_query_time Threshold, when the response time of the SQL statement exceeds the threshold, it will be recorded in the log
log_queries_not_using_indexes Queries that do not use indexes are also recorded in the slow query log, optional
log_output Log storage mode, the default is FILE. log_output='FILE' means save the log in a file. log_output='TABLE' means to store the log in the database. log_output='FILE,TABLE' means that the log will be stored in the file and the database at the same time

3. Configuration

#查看是否开启慢查询日志
show variables like 'slow%';

#临时开启慢查询日志
set slow_query_log='ON';
set long_query_time=1;

#慢查询日志文件所在位置
show variables like '%datadir%';

Guess you like

Origin blog.csdn.net/Jgx1214/article/details/107496108