Example of how to enable Slow query in MySQL

Example of how to enable Slow query in MySQL

Preface

Slow query log is a very important function in MySQL. We can enable the slow query log function of MySQL so that we can analyze the execution status and performance of each SQL statement and optimize it accordingly.

This article introduces the relevant content about enabling Slow query in MySQL. Let’s take a look at the detailed introduction.

Here’s how:

1: Log in to the database to check whether Slow query is enabled:

mysql> show variables like 'slow_query%';

2: Enable MySQL slow log:

By default, the value of slow_query_log is OFF, which means that the slow query log is disabled. You can enable it by setting the value of slow_query_log: (This is temporarily enabled and will become invalid after restarting the service. If you want to disable it permanently, remember to add a statement in the myqsl configuration file, see the end of the article)

mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.03 sec)

3: Check whether it is enabled:

mysql> show variables like 'slow_query%'; 

4: Write mysql slow statement to test whether slow data is written:

mysql> select sleep(10) as a, 1 as b; 

5: Check the Mysql Slow file to see if data is written:

At this point, the above Mysql slow startup job is completed!

--------------------------

Permanently enable MySQL Slow log:

slow_query_log_file slow query log file path

slow_query_log is used to specify whether to open the slow query log

long_query_time Queries exceeding this number of seconds are written to the log

log_output=file must specify a file or a table. If it is a table, the slow query information will be saved in the slow_log table under the mysql database. This point must be made clear. The default value is NONE

Open the my.cnf configuration file and add the following code:

log_output=file
slow_query_log=on ;
slow_query_log_file = /tmp/mysql-slow.log
long_query_time = 2

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. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • MySQL slow query method and example
  • Detailed explanation of the reason why the MySQL 5.7 slow query log time is 8 hours behind the system time
  • MySQL slow query operation example analysis [enable, test, confirm, etc.]
  • Causes and solutions for slow MySQL query speed and poor performance
  • Causes and solutions for slow MySQL queries
  • Reasons and solutions for slow MySQL query stuck in sending data
  • How to optimize MySQL performance through MySQL slow query
  • How to enable the slow query log function in MySQL
  • Basic usage tutorial of MySQL slow query log
  • Detailed explanation of MySQL slow queries

<<:  The pitfalls of deploying Angular projects in Nginx

>>:  Install Linux rhel7.3 operating system on virtual machine (specific steps)

Recommend

Ubuntu 16.04 image complete installation tutorial under VMware

This article shares with you the installation tut...

MySQL 5.7 zip archive version installation tutorial

This article shares the installation tutorial of ...

10 Tips to Improve Website Usability

Whether it is a corporate website, a personal blo...

...

MySQL 5.7.21 installation and configuration tutorial

The simple installation configuration of mysql5.7...

JS 9 Promise Interview Questions

Table of contents 1. Multiple .catch 2. Multiple ...

Detailed explanation of MySQL persistent statistics

1. The significance of persistent statistical inf...

mysql5.7 create user authorization delete user revoke authorization

1. Create a user: Order: CREATE USER 'usernam...

HTML basics HTML structure

What is an HTML file? HTML stands for Hyper Text M...

Best Practices Guide for MySQL Partitioned Tables

Preface: Partitioning is a table design pattern. ...

Detailed explanation of how to use the canvas operation plugin fabric.js

Fabric.js is a very useful canvas operation plug-...

Several methods of implementing carousel images in JS

Carousel The main idea is: In the large container...

A method of making carousel images with CSS3

Slideshows are often seen on web pages. They have...