English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Possiamo abilitare il log delle query lente di MySQL utilizzando la dichiarazione SET.
Ecco la sintassi.
SET GLOBAL slow_query_log = 'Value';
Nel sintassi sopra, il valore può essere riempito con ON / OFF. Per abilitare il log delle query lente, diamo un'occhiata alla query.
mysql> SET GLOBAL slow_query_log = 'ON';
Per controllare se la query lenta è attivata, esegui la seguente query-
mysql> SHOW GLOBAL VARIABLES LIKE 'slow\_%';
这是输出。
+---------------------+--------------------------+ | Variable_name | Value | +---------------------+--------------------------+ | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | DESKTOP-QN2RB3H-slow.log | +---------------------+--------------------------+ 3 rows in set (0.00 sec)
我们将慢速查询时间设置为秒,因为如果任何查询超出了给定的秒数,它将进入慢速查询日志文件。
我们还可以设置秒数。这是设置秒数的查询。
mysql> SET GLOBAL long_query_time = 20;
检查是否插入了时间。
mysql> SHOW GLOBAL VARIABLES LIKE 'long_query_time';
这是上面查询的输出。
+-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 20.000000 | +-----------------+-----------+ 1 row in set (0.00 sec)
完成上述任务后,我们需要刷新日志。
mysql> FLUSH LOGS;
注意-我们可以借助my.cnf文件永久禁用它。设置slow_query_log = 0; 禁用。