在线安全清空慢查询日志slowlog
mysql> show variables like '%slow_query%';
+------------------------------------+-------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------+
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+-------------------------------+
[root@trcloud-gtt-dw backup]# ls -l /data/DB/mysql/mysql-slow.log
-rw-rw---- 1 mysql mysql 2482474901 Jun 24 14:47 /data/DB/mysql/mysql-slow.log
发现慢查询日志已经有2G多了,使用mysqldumpslow统计信息的时候非常慢,需要在线清空并备份
一:关闭慢查询日志
mysql> set global slow_query_log=0;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%slow_query%';
+------------------------------------+-------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------+
| slow_query_log | OFF |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+-------------------------------+
6 rows in set (0.00 sec)
二:指定新的慢查询日志文件
mysql> set global slow_query_log_file='/data/DB/mysql/mysql-slow_20160624.log';
Query OK, 0 rows affected (0.00 sec)
三:开启慢查询日志
mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%slow_query%';
+------------------------------------+----------------------------------------+
| Variable_name | Value |
+------------------------------------+----------------------------------------+
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow_20160624.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+----------------------------------------+
6 rows in set (0.00 sec)
查看信息的慢查询日志文件
[root@trcloud-gtt-dw backup]# tail -50f /data/DB/mysql/mysql-slow_20160624.log
# Time: 160624 15:13:28
# User@Host: admin[admin] @ [172.30.250.103] Id: 20178
# Schema: gtt_api Last_errno: 0 Killed: 0
# Query_time: 0.000163 Lock_time: 0.000080 Rows_sent: 1 Rows_examined: 1 Rows_affected: 0
# Bytes_sent: 618
SET timestamp=1466752408;
SELECT invest_money, total_earning, invest_this_month, invest_last_month, total_wait_earning, total_people FROM th_home_data;
已经开始记录慢查询日志
四:备份老的慢查询日志文件
[root@trcloud-gtt-dw backup]# mv /data/DB/mysql/mysql-slow.log /backup/mysql-slow.log.bak.20160624
+------------------------------------+-------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------+
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+-------------------------------+
[root@trcloud-gtt-dw backup]# ls -l /data/DB/mysql/mysql-slow.log
-rw-rw---- 1 mysql mysql 2482474901 Jun 24 14:47 /data/DB/mysql/mysql-slow.log
发现慢查询日志已经有2G多了,使用mysqldumpslow统计信息的时候非常慢,需要在线清空并备份
一:关闭慢查询日志
mysql> set global slow_query_log=0;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%slow_query%';
+------------------------------------+-------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------+
| slow_query_log | OFF |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+-------------------------------+
6 rows in set (0.00 sec)
二:指定新的慢查询日志文件
mysql> set global slow_query_log_file='/data/DB/mysql/mysql-slow_20160624.log';
Query OK, 0 rows affected (0.00 sec)
三:开启慢查询日志
mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%slow_query%';
+------------------------------------+----------------------------------------+
| Variable_name | Value |
+------------------------------------+----------------------------------------+
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow_20160624.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+----------------------------------------+
6 rows in set (0.00 sec)
[root@trcloud-gtt-dw backup]# tail -50f /data/DB/mysql/mysql-slow_20160624.log
# Time: 160624 15:13:28
# User@Host: admin[admin] @ [172.30.250.103] Id: 20178
# Schema: gtt_api Last_errno: 0 Killed: 0
# Query_time: 0.000163 Lock_time: 0.000080 Rows_sent: 1 Rows_examined: 1 Rows_affected: 0
# Bytes_sent: 618
SET timestamp=1466752408;
SELECT invest_money, total_earning, invest_this_month, invest_last_month, total_wait_earning, total_people FROM th_home_data;
已经开始记录慢查询日志
四:备份老的慢查询日志文件
[root@trcloud-gtt-dw backup]# mv /data/DB/mysql/mysql-slow.log /backup/mysql-slow.log.bak.20160624