MySQL – OPTIMIZE all tables with PHP and mysqli

$alltables = mysqli_query($conn, "SHOW TABLES");

while ($table = mysqli_fetch_assoc($alltables)){

    foreach ($table as $db => $tablename){

        echo "OPTIMIZE TABLE `".$tablename."`";
        mysqli_query($conn, "OPTIMIZE TABLE `".$tablename."`") or die(mysqli_error());
        echo "<br>";
    }

}

Leave a Comment

Your email address will not be published. Required fields are marked *