在 MySQL 中截断慢查询日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/577339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Truncate Slow Query Log in MySQL
提问by Greg
What's the safest way to truncate the MySQL slow query log (under Linux primarily, but Windows would be handy to know) while MySQL is running?
在 MySQL 运行时截断 MySQL 慢查询日志的最安全方法是什么(主要在 Linux 下,但 Windows 会很方便地知道)?
By safe I mean:
安全我的意思是:
- Mustn't cause any permissions problems
- Mustn't jump back to its original size next time its appended to
- 不得引起任何权限问题
- 下次附加到时不能跳回原来的大小
回答by vartec
To truncate a file regardless if it is open by a running application do:
要截断文件,无论它是否被正在运行的应用程序打开,请执行以下操作:
> /var/logs/your.log
at your shell prompt.
在你的 shell 提示符下。
回答by tjanofsky
回答by Luke Francl
If this is going to be a ongoing concern, you should take a look at logrotateas it can do this for you.
如果这将是一个持续的问题,您应该看看logrotate,因为它可以为您做到这一点。
I did not know about echo > file.log
, though it makes sense. I've always used cat /dev/null > file.log
.
我不知道关于echo > file.log
,虽然它是有道理的。我一直都在用cat /dev/null > file.log
。
Also, it should be noted that it's veryimportant not to delete a log file that is being written to because the program that has it open will continue to write to the file. Very difficult to figure out why all your hard drive space is gone!
另外,应该注意的是,不要删除正在写入的日志文件非常重要,因为打开它的程序将继续写入文件。很难弄清楚为什么你所有的硬盘空间都不见了!