Get the App
SLTechnology News&Howtos  ›  Database  › 

How to enable Slow slow query in MySQL

Shulou Source: shulou.com Published: 2022-05-31 22:44:27 10月02日 Update

This article introduces how to open Slow slow query in MySQL, the content is very detailed, interested friends can refer to, hope to be helpful to you.

The methods are as follows:

1: log in to the database to see if Slow slow query has been 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 slow log is disabled, which can be enabled by setting the value of slow_query_log: (here, it will expire after restarting the service. If you want to fail permanently, please add a statement to 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 the data is written:

So far, complete the above Mysql slow start-up operations!

-

Permanently open the 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.

Queries over how many seconds of long_query_time are written to the log.

Log_output=file must specify either file or table. If it is table, the slow query information is saved to the slow_ log table under the mysql library. Be clear about this. The default value is NONE

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

Log_output=fileslow_query_log=on; slow_query_log_file = / tmp/mysql-slow.loglong_query_time = 2 so much about how to enable Slow slow query in MySQL. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Tags: Query log file data content more statement permanent help configuration good clear code information interest can be passed guys partners situation database Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Shulou Tech Info Apple MariaDB