I was logging slow queries of my system. Now I have few queries to be optimized and reset the global slow_query_log
variable to 0
. Now I want to delete slow query log file mysqld-slow.log
. can anyone tell me what is the standard way to do this ?
I am using Cent OS and do not want to delete or affect other log files (i.e. general log or binary log) Thanks.
5 Answers 5
As of 5.5.3, FLUSH LOGS
will close and reopen the slowlog. (In old versions, FLUSH
had no effect on the slowlog.)
So, on *nix OS, this should work without restarting the server:
rm
(to delete) ormv
the slowlog to another name. (Note: mysqld will continue to write to the file, even though you changed the name.)FLUSH LOGS;
. As of 5.5.3, you can limit the effect viaFLUSH SLOW LOGS;
See http://bugs.mysql.com/bug.php?id=14104 and http://bugs.mysql.com/bug.php?id=60878
I would not turn off the slowlog -- next month someone will add a naughty query and you will want to know about it.
or set
SET GLOBAL slow_query_log = 'OFF';
then clear the file and then
SET GLOBAL slow_query_log = 'ON';
It's very simple. If you want the slow query log file just take the backup and do below.
tail -n slow-query.log > slow-query.log
The above file will recreate with 'n' number of line with same name which clears the space.
-
Is this safe while the mysql service running?fat_mike– fat_mike2021年01月21日 13:03:05 +00:00Commented Jan 21, 2021 at 13:03
Let me tell you, how I did that.
- Stop the mysql service.
- Backup / Copy the existing slow query log to another directory or folder.
- Remove / Move the log file to another directory.
- Create a new log file with the same name.
- Start the mysql service.
Note:
- Make sure, you have rights to move/remove the log file.
- You cannot delete the file, when mysql service is accessing the log file.
This worked for me, I hope it will help you too. Thanks.
In case you are using AWS RDS service, trying to
>truncate mysql.slow_log;
Error Code: 1044. Access denied for user 'rds_admin'@'%' to database 'mysql'
The RDS way to do this, is to call built-in function which will move slow_log table to slow
CALL mysql.rds_rotate_slow_log;
Explore related questions
See similar questions with these tags.