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

MySQL slow query-enable slow query

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I. brief introduction

By enabling the slow query log, you can let MySQL record the statements that query for more than a specified time. By locating the bottleneck of analyzing performance, you can better optimize the performance of the database system.

Second, parameter description

Slow_query_log slow query enabled status

The location where the slow_query_log_file slow query log is stored (this directory requires the writable permission of the running account of MySQL, which is generally set to the data storage directory of MySQL)

How many seconds does the long_query_time query take to record

3. Setting steps

1. View parameters related to slow query

Mysql > show variables like 'slow_query%' +-- +-- + | Variable_name | Value | + -- + | slow_query_log | OFF | | slow_query_log_file | / mysql/data/localhost-slow.log | +-- -+ mysql > show variables like 'long_query_time' +-+ | Variable_name | Value | +-+-+ | long_query_time | 10.000000 | +-+-+

two。 Setting method

Method 1: global variable setting

Set the slow_query_log global variable to the "ON" state

Mysql > set global slow_query_log='ON'

Set the location where slow query logs are stored

Mysql > set global slow_query_log_file='/usr/local/mysql/data/slow.log'

Record the query for more than 1 second.

Mysql > set global long_query_time=1

Method 2: profile settings

Modify the configuration file my.cnf and add under [mysqld]

[mysqld] slow_query_log = ONslow_query_log_file = / usr/local/mysql/data/slow.loglong_query_time = 1

3. Restart the MySQL service

Service mysqld restart

4. View the parameters after setting

Mysql > show variables like 'slow_query%' +-+ | Variable_name | Value | +-+- -+ | slow_query_log | ON | | slow_query_log_file | / usr/local/mysql/data/slow.log | +-- + mysql > show variables like 'long_query_time' +-+-+ | Variable_name | Value | +-+-+ | long_query_time | 1.000000 | +-+-+ 4. Test

1. Execute a slow query SQL statement

Mysql > select sleep (2)

two。 Check to see if slow query logs are generated

Ls / usr/local/mysql/data/slow.log

If the log exists, the slow query setting enabled by MySQL is successful!

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