Created
May 19, 2021 10:23
-
-
Save Tim-Schwalbe/23ca6e3ee4968c954e3b2367c1c9edc8 to your computer and use it in GitHub Desktop.
Optimize multiple MySQL Tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set @tables_like = "%table_name%"; | |
set @optimize = null; | |
set @show_tables = concat("show tables where", ifnull(concat(" `Tables_in_", database(), "` like '", @tables_like, "' and"), ''), " (@optimize:=concat_ws(',',@optimize,`Tables_in_", database() ,"`))"); | |
Prepare `bd` from @show_tables; | |
EXECUTE `bd`; | |
DEALLOCATE PREPARE `bd`; | |
set @optimize := concat('optimize table ', @optimize); | |
PREPARE `sql` FROM @optimize; | |
EXECUTE `sql`; | |
DEALLOCATE PREPARE `sql`; | |
set @show_tables = null, @optimize = null, @tables_like = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment