Last active
December 22, 2015 20:19
-
-
Save rmulley/6525574 to your computer and use it in GitHub Desktop.
Searches MySQL general log for unclosed prepared statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
my %pids; | |
#open log file | |
open LOG, "<mysql-general.log"; | |
#check file opened properly | |
if(!fileno(LOG)) { | |
die("mysql-general.log file not found!\n"); | |
}#if | |
#get every line of file, one at a time | |
while(my $line = <LOG>) { | |
#check for a prepared query | |
if($line =~ m!^\s*(\d+)\s+Prepare!is) { | |
#capture process ID | |
$pids{"$1"} = 1; | |
} else { | |
#check to see if a open prepared statement has been closed | |
for(keys %pids) { | |
#if a closed statement, remove process ID from hash of open IDs | |
if($line =~ m!^\s*$_\s+Close\s+stmt!is) { | |
delete $pids{"$_"}; | |
}#if | |
}#for | |
}#else | |
}#while | |
close(LOG); | |
print("The following statements were not closed:\n"); | |
for(keys %pids) { | |
print($_."\n"); | |
}#for | |
print("\n\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment