一、清除原因
因为之前打开了慢查询,导致此表越来越大达到47G,导致磁盘快被占满,使用xtrabackup进行备份的时候文件也超大。
mysql> show variables like 'log_output%'; Connection id: 1694401091 Current database: mysql +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | TABLE | +---------------+-------+ 1 row in set (0.00 sec) mysql> show variables like '%slow%'; +---------------------+-------------------------------------+ | Variable_name | Value | +---------------------+-------------------------------------+ | log_slow_queries | ON | | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | /home/mysql/data3311/sql01-slow.log | +---------------------+-------------------------------------+ 4 rows in set (0.00 sec)
现在备份之前的文件夹大小只有3.1G,备份后大小3.3G,使用mysqldump逻辑备份数据库为234M。
二、清理show_log的方法
mysql> use mysql; mysql> SET GLOBAL slow_query_log = 'OFF'; mysql> ALTER TABLE slow_log RENAME slow_log_drop; mysql> CREATE TABLE slow_log LIKE slow_log_drop; mysql> SET GLOBAL slow_query_log = 'ON'; mysql> DROP TABLE slow_log_drop;
三、相关参数
mysql> show variables like '%log_output%'; # 默认是FILE +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | TABLE | +---------------+-------+ 1 row in set (0.00 sec) mysql> show variables like '%quer%'; Connection id: 1694418241 Current database: *** NONE *** +-------------------------------+-------------------------------------+ | Variable_name | Value | +-------------------------------+-------------------------------------+ | ft_query_expansion_limit | 20 | | have_query_cache | YES | | log_queries_not_using_indexes | ON | | log_slow_queries | ON | | long_query_time | 2.000000 | | query_alloc_block_size | 8192 | | query_cache_limit | 2097152 | | query_cache_min_res_unit | 4096 | | query_cache_size | 67108864 | | query_cache_type | OFF | | query_cache_wlock_invalidate | OFF | | query_prealloc_size | 8192 | | slow_query_log | ON | | slow_query_log_file | /home/mysql/data3311/sql01-slow.log | +-------------------------------+-------------------------------------+ 14 rows in set (0.00 sec) -- log_output 默认是FILE,表示慢查询日志输入至日志文件,可以通过set修改输出为TABLE -- log_queries_not_using_indexes 默认是OFF,表示是否记录没有使用索引的查询 -- slow_query_log 默认是OFF,表示是否打开慢查询 -- long_query_time默认是 10.000000,表示记录超过时间的慢查询 SET global slow_query_log = OFF; # 打开慢查询记录 SET GLOBAL long_query_time = 2.000000; # 记录超过2秒的慢查询句语 SET GLOBAL log_queries_not_using_indexes = ON; # 开启 记录没有使用索引的语句 SET global log_output='TABLE' # 默认为FILE,改为TABLE