Skip to content

Instantly share code, notes, and snippets.

@hexatridecimal
Created August 25, 2014 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexatridecimal/08b2c51c8d2e15ae171b to your computer and use it in GitHub Desktop.
Save hexatridecimal/08b2c51c8d2e15ae171b to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use DBI;
use Data::Dumper qw/Dumper/;
my $query = shift(@ARGV);
my $dbh = DBI->connect('dbi:mysql:database=', 'root', 'YoPassword');
my $sth = $dbh->prepare("SHOW PROCESSLIST");
while (1) {
$sth->execute();
my $ret = $sth->fetchall_arrayref();
$found = 0;
foreach my $row (@$ret) {
if ($row->[7] =~ /$query/) {
$found = 1;
}
}
if ($found == 0) {
print "Not found!\a\n";
} else {
print "Yup, still running!\n";
}
sleep(5);
}
@hexatridecimal
Copy link
Author

I've found this really useful. Use like:

./watch_mysql.pl "alter table x"

This will ring a bell when the query finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment