mysql> show variables like '%slow_query_log%';
+---------------------+-------------------------------------+
| Variable_name | Value |
+---------------------+-------------------------------------+
| slow_query_log | ON |
| slow_query_log_file | /opt/mysql/data/3306/mysql-slow.log |
+---------------------+-------------------------------------+
mysql> set global slow_query_log=0;
mysql> show variables like '%slow_query_log%';
+---------------------+-------------------------------------+
| Variable_name | Value |
+---------------------+-------------------------------------+
| slow_query_log | OFF |
| slow_query_log_file | /opt/mysql/data/3306/mysql-slow.log |
+---------------------+-------------------------------------+
mv /opt/mysql/data/3306/mysql-slow.log /opt/mysql/data/3306/mysql-old-slow.log
mysql> set global slow_query_log=1;
mysql> select sleep(5);
+----------+
| sleep(5) |
+----------+
| 0 |
+----------+
cat /opt/mysql/data/3306/mysql-slow.log
[root@DMP1 3306]# cat mysql-slow.log
/opt/mysql/base/5.7.31/bin/mysqld, Version: 5.7.31-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306 Unix socket: /opt/mysql/data/3306/mysqld.sock
Time Id Command Argument
# Time: 2021-01-05T13:26:44.001647+08:00
# User@Host: root[root] @ localhost [] Id: 81786
# Query_time: 5.000397 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1609824404;
select sleep(5);
mv /opt/mysql/data/3306/mysql-old-slow.log /mysqlback