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

Vue implements local storage add, delete and modify functions

This article example shares the specific code of ...

HTML5+CSS3 coding standards

The Golden Rule No matter how many people are wor...

12 Javascript table controls (DataGrid) are sorted out

When the DataSource property of a DataGrid control...

Sample code for implementing image drawer effect with CSS3

As usual, let’s first post the picture effect: Th...

Some small methods commonly used in html pages

Add in the <Head> tag <meta http-equiv=&q...

How to quickly install RabbitMQ in Docker

1. Get the image #Specify the version that includ...

How to optimize the slow Like fuzzy query in MySQL

Table of contents 1. Introduction: 2. The first i...

Web Design Tutorial (6): Keep your passion for design

<br />Previous article: Web Design Tutorial ...

Tutorial on upgrading from Centos7 to Centos8 (with pictures and text)

If you upgrade in a formal environment, please ba...

A brief introduction to MySQL functions

Table of contents 1. Mathematical functions 2. St...

Building .NET Core 2.0 + Nginx + Supervisor environment under Centos7 system

1. Introduction to Linux .NET Core Microsoft has ...

CocosCreator learning modular script

Cocos Creator modular script Cocos Creator allows...