mysql slow query log

Check if MySQL is enabled to view log files for slow SQL

 

( 1) Check whether the slow SQL log is enabled

 

mysql> show variables like 'log_slow_queries';

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| log_slow_queries | ON    |

+------------------+-------+

1 row in set (0.00 sec)

 

( 2) Check how many seconds slower SQL execution will be recorded in the log file

mysql> show variables like 'long_query_time';

+-----------------+-------+

| Variable_name   | Value |

+-----------------+-------+

| long_query_time | 1     |  

+-----------------+-------+

1 row in set (0.00 sec)

 

Here value=1, which means 1 second

 

Find mysql.ini in the [mysqld] section, and add the log configuration, as shown in the following example:

slow_query_log = on

slow_query_log_file = C:/soft/1.log

long_query_time = 0.03

 

slow_query_log=on indicates that slow log is enabled

slow_query_log_file indicates the sql log directory that records the long execution time ;

long_query_time indicates how long is the execution time, in s.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325908168&siteId=291194637