perl <<'EOF'
#!/usr/bin/perl

use DBI;
use strict;

my $database = "dbname_placeholder";

my $rootpass;
open(DAT, "/root/.my.cnf") || die "FATAL ERROR: There is no /root/.my.cnf, rectify this immediately.";
    while (<DAT>) {
            if ( /=/ ) {
            my ( $key, $value ) = split(/=/);
            if ( $key =~ /^pass/ ) { 
                $rootpass = $value;
                last;
            }
            }
    }
close(DAT);

$rootpass =~ s/[\"\']//g;
chomp($rootpass);

if ( ! $rootpass ) {
    die "[!] Unable to determine root password from /root/.my.cnf!\n";
}

my $dsn = "DBI:mysql:database=$database;host=localhost;port=3306";
my $dbh = DBI->connect($dsn, 'root', $rootpass);

my $prefixresult = $dbh->prepare("show tables");
$prefixresult->execute;

my @tables;

while (my $prefixref = $prefixresult->fetchrow_arrayref() ) {
        foreach my $thistable (@$prefixref) {
                push(@tables,$thistable);
        }
}

foreach my $thistable (@tables) {
    print "[*] Checking $thistable...\n";
        print "\t - Locking\n";
        my $lock = $dbh->prepare("LOCK TABLE $thistable write");
        $lock->execute;
        print "\t - Flushing\n";
        my $flush = $dbh->prepare("FLUSH TABLE $thistable");
        $flush->execute;
        print "\t - Repairing\n";
        my $repair = $dbh->prepare("REPAIR TABLE $thistable");
        $repair->execute;
        my $flush = $dbh->prepare("FLUSH TABLE $thistable");
        $flush->execute;
        print "\t - Unlocking\n";
        my $unlock = $dbh->prepare("unlock table");
        $unlock->execute;
}

EOF
