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

Summary of several error logs about MySQL MHA setup and switching

1: masterha_check_repl replica set error replicat...

HTML+CSS to create a top navigation bar menu

Navigation bar creation: Technical requirements: ...

JavaScript adds event listeners to event delegation in batches. Detailed process

1. What is event delegation? Event delegation: Ut...

Some functions of using tcpdump to capture packets in the Linux command line

tcpdump is a flexible and powerful packet capture...

jQuery implements employee management registration page

This article example shares the specific code of ...

Mobile Internet Era: Responsive Web Design Has Become a General Trend

We are in an era of rapid development of mobile In...

5 ways to achieve the diagonal header effect in the table

Everyone must be familiar with table. We often en...

Explanation on whether to choose paging or loading in interactive design

The author of this article @子木yoyo posted it on hi...

MySQL Full-text Indexing Guide

Full-text indexing requires special query syntax....

Detailed explanation of several ways to create objects and object methods in js

This article is the second article about objects ...

jQuery implements form validation

Use jQuery to implement form validation, for your...

Solution to span width not being determined in Firefox or IE

Copy code The code is as follows: <html xmlns=...