Detailed explanation of how to enable slow query log in MySQL database

Detailed explanation of how to enable slow query log in MySQL database

The database enables slow query logs

Modify the configuration file

Add the following two sentences to the configuration file my.ini

log-slow-queries = C:\xampp\mysql_slow_query.log
long_query_time=3

The first sentence is used to define the path of the slow query log (if it is a Linux system, it will involve permission issues)

The second sentence is used to define queries that take more than a certain number of seconds as slow queries, in seconds.

Check whether the configuration is successful:

//View the slow query time, unit: s
show variables like "long_query_time";
//View the slow query configuration show status like "%slow_queries%";
//View the slow query log path show variables like "%slow%";
 

Execute a slow query operation to verify whether the log is recorded:

The amount of data in the environment you build is small, so it is difficult to simulate the execution of slow queries. You can use the following statement to simulate instead:

SELECT SLEEP(10), name from user where userid=1;

 

View the number of slow queries:

show global status like '%slow%';

Thank you for reading, I hope it can help you, thank you for your support of this site!

You may also be interested in:
  • Detailed explanation of MySql slow query analysis and opening slow query log
  • How to enable MySQL slow query log log-slow-queries
  • Tips for enabling slow query log in MYSQL5.7.9
  • mysql enable slow query how to enable mysql slow query logging
  • How to enable slow query log in MySQL
  • How to enable the slow query log function in MySQL
  • The role and opening of MySQL slow query log
  • Enabling and configuring MySQL slow query log
  • MySQL optimization solution: enable slow query log

<<:  How to use rem adaptation in Vue

>>:  Detailed explanation of basic operation commands such as starting and stopping Nginx under Windows

Recommend

Description of the default transaction isolation level of mysql and oracle

1. Transaction characteristics (ACID) (1) Atomici...

An article to understand the use of proxies in JavaScript

Table of contents What is an agent Basic knowledg...

VMWare15 installs Mac OS system (graphic tutorial)

Installation Environment WIN10 VMware Workstation...

Detailed explanation of uniapp's global variable implementation

Preface This article summarizes some implementati...

Newbies quickly learn the steps to create website icons

<br />Original URL: http://www.lxdong.com/po...

How to configure https for nginx in docker

Websites without https support will gradually be ...

Docker Compose installation and usage steps

Table of contents 1. What is Docker Compose? 2. D...

Detailed explanation of this pointing problem in JavaScript

Preface The this pointer in JS has always been a ...

The use of anchor points in HTML_PowerNode Java Academy

Now let's summarize several situations of con...

MySQL detailed summary of commonly used functions

Table of contents MySQL Common Functions 1. Numer...

Connector configuration in Tomcat

JBoss uses Tomcat as the Web container, so the co...

Simple steps to create a MySQL container with Docker

Preface We have already installed Docker and have...