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 enable slow log check by MySQL

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

Share

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

Editor to share with you how to start MySQL slow check log, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

In the development project, we can monitor the SQL of efficiency problems through the slow query log of MySQL.

Some of the following commands open the log:

Find the directory of the slow query log file

Show variables like 'slow_query_log'

Set up slow log files directory files

Set global slow_query_log_file='home/mysql/sql_log/mysql_slow.log'

Whether to record the sql without using the index in the log

Set global log_queries_not_using_indexes=on

Sets the number of seconds sql is recorded in the log

Set global long_query_time=1

This time is usually relatively large here, it is better to set it at 0.01s, depending on your own situation.

Let's actually execute the command:

First check the log file location:

You can see that our slow_query_log is off, which means we have not enabled slow log checking.

Check the status of the log through the show variables like'% log' command, if our log_queries_not_using_indexes option is OFF

Then we need to set it to on.

Then use the command to see if the value of long_query_time is set. If it is 0, it means that no matter what the query is, it will be recorded in the log.

It is important to note that in the build environment, there may be a large number of logs in a short period of time.

Let's take a look at the storage format of the log:

The format is as follows:

# query execution time # Time:140606 12:30:17#SQL execution host information # User@Host:root [root] @ localhost [] # SQL execution information, query execution time lock time number of rows sent and number of rows scanned # Query_time:0.000031 Locak_time:0.000000 Rows_sent:0 Rows_examined:0 # SQL execution time SQL content show tables executed by SET timestamp=1402029017;# The above is all the contents of the article "how to start slow checking logs in MySQL". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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