背景:
在排查mysql的锁等待,死锁和其他事务性相关的问题中,经常需要排查mysql,根据thread id 找到问题事务
#!/usr/bin/perl -w
while(<>)
{
chomp($_);
if($_ =~ m/(Query|Connect)/g){
print "\n",$_;
next;
}elsif($_ =~ m/^\s*$/g){
next;
}else{
$_ =~ s/^\s+|\s+$//g;
print " ",$_;
}
}
使用效果比如说
7503587 Query select
a,b,c
from
t
变成如下
7503587 Query select a,b,c from t