Detailed analysis of the MySQL slow log opening method and storage format

Detailed analysis of the MySQL slow log opening method and storage format

In development projects, we can monitor SQL with efficiency issues through MySQL's slow query log.

The following commands enable logging:

Find the directory for slow query log files

show variables like 'slow_query_log'

Set the slow log file directory

set global slow_query_log_file='home/mysql/sql_log/mysql_slow.log'

Whether to record SQL statements that do not use indexes in the log

set global log_queries_not_using_indexes=on

Set the number of seconds that SQL statements that exceed this limit are recorded in the log.

set global long_query_time=1

Here this time is usually quite large, it is best to set it to 0.01s, depending on your own situation.

Now let's actually execute the command:

First check the log file location:

It can be seen that our slow_query_log is off, which means that we have not enabled the slow query log.

Use show variables like '%log' command to view the status of the log. If our log_queries_not_using_indexes option is OFF,
Then we need to set it to on.

Then use the command to check whether the value of long_query_time is set. If it is 0, it means that all queries will be recorded in the log.
It should be noted that in a production environment, there may be a large amount of logs in a short period of time.

Let's take a look at the log storage format:

The format is as follows:

#Query execution time#Time:140606 12:30:17
#SQL execution host information #User@Host:root[root] @ localhost []
#SQL execution information, query execution time, lock time, number of rows sent and number of rows scanned #Query_time:0.000031 Locak_time:0.000000 Rows_sent:0 Rows_examined:0 
#SQL execution time SET timestamp=1402029017;
#Executed SQL content show tables;

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of MySql slow query analysis and opening slow query log
  • mysql enable slow query how to enable mysql slow query logging
  • Tips for enabling slow query log in MYSQL5.7.9
  • How to enable MySQL slow query log log-slow-queries
  • MySQL slow query optimization and slow query log analysis example tutorial
  • How to enable slow query log in MySQL
  • How to correctly and safely clear the online slow query log in MySQL
  • Basic tutorial on analyzing MySQL slow query log
  • Monitor SQL statement execution efficiency based on MySQL slow log
  • Basic learning tutorial on query log and slow query log in MySQL

<<:  Detailed tutorial on installing JDK8 on Linux system (CentOS7 installation)

>>:  Summary of webpack's mobile adaptation solution

Recommend

An exploration of the JS operator in problem

Here's the thing: Everyone knows about "...

How to use video.js in vue to play m3u8 format videos

Table of contents 1. Installation 2. Introducing ...

v-html rendering component problem

Since I have parsed HTML before, I want to use Vu...

js to achieve star flash effects

This article example shares the specific code of ...

JS realizes the effect of Baidu News navigation bar

This article shares the specific code of JS to ac...

Summary of MySQL common SQL statements including complex SQL queries

1. Complex SQL queries 1.1. Single table query (1...

TimePicker in element disables part of the time (disabled to minutes)

The project requirements are: select date and tim...

JavaScript implements mouse drag to adjust div size

This article shares the specific code of JavaScri...

A brief summary of my experience in writing HTML pages

It has been three or four months since I joined Wo...

Detailed discussion of the character order of mysql order by in (recommended)

//MySQL statement SELECT * FROM `MyTable` WHERE `...

mysql5.7.21.zip installation tutorial

The detailed installation process of mysql5.7.21 ...

In-depth understanding of Vue's method of generating QR codes using vue-qr

Table of contents npm download step (1) Import (2...

Example code for CSS pseudo-classes to modify input selection style

Note: This table is quoted from the W3School tuto...

Summary of Textarea line break issues in HTML

Recently, I encountered a problem of whether the d...