mysql> SHOW VARIABLES LIKE 'slow_query%'; +---------------------+---------------------------------------------------------------------+ | Variable_name | Value | +---------------------+---------------------------------------------------------------------+ | slow_query_log | OFF | | slow_query_log_file | C:\ProgramData\MySQL\MySQL Server 5.7\Data\LAPTOP-UHQ6V8KP-slow.log | +---------------------+---------------------------------------------------------------------+ 2 rows in set, 1 warning (0.02 sec) mysql> SHOW VARIABLES LIKE 'long_query_time'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+ 1 row in set, 1 warning (0.01 sec)参数说明如下:
[mysqld]
log-slow-queries=dir\filename
long_query_time=n
SET GLOBAL slow_query_log=ON/OFF;
SET GLOBAL long_query_time=n;
mysql> SET GLOBAL slow_query_log=ON; Query OK, 0 rows affected (0.05 sec) mysql> SET GLOBAL long_query_time=0.001; Query OK, 0 rows affected (0.00 sec)由于需要演示这里我们将时间设置为了 0.001 秒,执行时间超过 0.001 秒的 SQL 语句将被记录到日志中。
mysql> USE test; Database changed mysql> SELECT * FROM tb_student; +----+--------+ | id | name | +----+--------+ | 1 | Java | | 2 | MySQL | | 3 | Python | +----+--------+ 3 rows in set (0.08 sec)相应的,慢查询日志的部分内容如下:
# Time: 2020-06-01T01:59:18.368780Z # User@Host: root[root] @ localhost [::1] Id: 3 # Query_time: 0.006281 Lock_time: 0.000755 Rows_sent: 2 Rows_examined: 1034 use test; SET timestamp=1590976758; SHOW VARIABLES LIKE 'slow_query%';
mysqladmin -uroot -p flush-logs
执行该命令后,命令行会提示输入密码。输入正确密码后,将执行删除操作。新的慢查询日志会直接覆盖旧的查询日志,不需要再手动删除。
本文链接:http://task.lmcjl.com/news/15760.html