Get the App
SLTechnology News&Howtos  ›  Database  › 

How to enable mysql to view slow query logs

Shulou Source: shulou.com Published: 2022-05-31 17:54:56 10月04日 Update

This article mainly explains "how to open mysql to view slow query log". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to open mysql to view slow query logs".

Environment: percona5.6.27

Check whether the function of viewing slow query logs has been enabled in the database

Mysql > show variables like'% slow%'

+-+

| | Variable_name | Value |

+-+

| | log_slow_admin_statements | OFF |

| | log_slow_filter |

| | log_slow_rate_limit | 1 | |

| | log_slow_rate_type | session |

| | log_slow_slave_statements | OFF |

| | log_slow_sp_statements | ON |

| | log_slow_verbosity |

| | max_slowlog_files | 0 | |

| | max_slowlog_size | 0 | |

| | slow_launch_time | 2 | |

| | slow_query_log | OFF |

| | slow_query_log_always_write_time | 10.000000 | |

| | slow_query_log_file | / disk/DB/mysql/trcloud-wujian-test01-slow.log |

| | slow_query_log_timestamp_always | OFF |

| | slow_query_log_timestamp_precision | second |

| | slow_query_log_use_global_control |

+-+

16 rows in set (0.01 sec)

Parameter slow_query_log indicates whether to enable slow query log.

The slow_launch_time parameter indicates how many seconds the query will be recorded in the slow log.

The slow_query_log_file parameter indicates a slow log file

Now modify the my.cnf file to set the following content

Slow-query-log=1

Slow-launch-time=30

Restart the database service mysql restart.

Of course, you can also use set global slow-query-log=1 to modify the parameters.

At this point, I believe you have a deeper understanding of "how to open mysql to view slow query logs". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Logs queries parameters content data databases files learning practical deeper interests functions practicality practicality simple operation methods methods more friends environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Technology Shulou Tech Info Huawei OPPO Reno