Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure slow query in mysql

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Mysql how to configure slow query, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Slow query configuration

MYSQL slow query

1. What's the use of slow inquiry?

It can record all the SQL statements that exceed the long_query_time time, help you find the slow SQL, and facilitate us to optimize these SQL.

two。 How to open a slow query?

First of all, let's check whether the slow query status of the MYSQL server is enabled.

Execute the following command:

We can see that the current log_slow_queries status is OFF, indicating that slow queries are not currently open.

It is very easy to enable slow query. The operations are as follows:

Method 1: find the configuration file my.cnf (/ etc/my.cnf) of mysql, and add a slow query configuration statement under mysqld (Note: be sure to add it under [mysqld]. If you add a configuration statement under [mysqld_safe], it will not take effect. I made this mistake in the process of configuration and experienced the pain myself!

Log-slow-queries: represents the log storage directory of MYSQL slow query. This directory file must have write permission.

Long_query_time: maximum execution time. (as shown in the figure, MSYQL will record all SQL statements with more than 2 execution times. Here, the test time should not be too small, preferably within 5-10 seconds. Of course, it can be determined according to your own standards)

Restart a MYSQL after configuration:

Service mysqld restart

Method 2: do the following under the mysql command line: (solve ing)

Set the state of the MYSQL variable through the set command. But I failed the test all the time, and I suspect it may be the MYSQL version.

Www.2cto.com

I found a lot of information on the Internet, but it has not been solved. I hope the master passing by can help me answer it.

After the configuration is complete, let's take a look at the current status; you will find the following:

Indicates that the slow query service has been turned on, and the time limit is 2 seconds.

Let's take another look at whether the mysql-slow.log file is automatically created under the / var/lib/mysql/ directory.

Cat mysql-slow.log found that the file already exists. Only there is no record of the task SQL in the file. So now let's test and execute a SQL statement that exceeds long_query_time.

After executing a 3-second SQL statement, the SQL statement should be recorded in the mysql-slow.log file. OK! Let's cat mysql-slow.log.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report