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>"; } }

MySql Update with Inner Join

If you need to run an UPDATE in MySql on some rows in a table, but the reference of the condition to use is in another table, the best solution is to use an UPDATE…