mysqldumpslow的选择中,没有开始、结束时间的选项。
截断slow日志文件最常规做法,不过很麻烦不是。怎么办才更优雅?
最最最佳做法:使用sed 模式范围
sed -n '/Time: 2022-12-20/,/Time: 2022-12-21/p' /data/mysql/slow.log | mysqldumpslow -s at -n 10 - | more
sed -n '/Time: 2022-12-20/,/Time: 2022-12-21/p' /data/mysql/slow.log | mysqldumpslow -s at -n 10 - | more
sed -n '/Time: 2022-12-20/,/Time: 2022-12-21/p' /data/mysql/slow.log | mysqldumpslow -s at -n 10 - | more
grep -A -B 在大文件情况下 !!!性能有严重问题!!!!
不推荐!!!
grep -A 999999999 "Time: 2022-12-20" /data/mysql/slow.log | grep -B 999999999 "Time: 2022-12-21" /data/mysql/slow.log | mysqldumpslow -s at -n 10 - | more
复杂、高级、灵活的 awk
#!/sh/awk BEGIN { i=0; j=0; } { if ($0 ~ /# Time: 2022-12-20.*/) { i=1; } if (i==1) { j++; print $0; if ($0 ~ /# Time: 2022-12-21.*/) i=0; } } END { print "lines: " j; }
标签:slow,12,mysqldumpslow,stoptime,2022,Time,log From: https://www.cnblogs.com/jinzhenshui/p/17012248.html