Skip to content

Instantly share code, notes, and snippets.

@rushipkar90
Last active March 1, 2020 10:01
Show Gist options
  • Save rushipkar90/bae79bdf263b14ec2ae6 to your computer and use it in GitHub Desktop.
Save rushipkar90/bae79bdf263b14ec2ae6 to your computer and use it in GitHub Desktop.
mysqlslowq.pl
#!/usr/bin/perl
%accounts = ();
$lines = `grep ^# /var/log/mysql_slow_query.log`;
$correctMonth = 0;
foreach (split("\n", $lines)) {
chomp;
if ($_ =~ /# User\@Host: ([a-z0-9_]+)/) {
$db = $1;
if ($db =~ /_/) {
($user, @blah) = split('_', $db);
$accounts{$user} = $db;
} else {
$accounts{'system'} = $db;
}
}
}
@sorted = sort keys(%accounts);
$format = "%-15s %-13s\n";
print "\nDATABASES WITH SLOW QUERIES\n\n";
printf $format, $_, $accounts{$_} for (@sorted);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment