Skip to content

Instantly share code, notes, and snippets.

@elfeffe
Created April 8, 2016 11:09
Show Gist options
  • Save elfeffe/06d3f00182370c6ecbf0bc33d59e1103 to your computer and use it in GitHub Desktop.
Save elfeffe/06d3f00182370c6ecbf0bc33d59e1103 to your computer and use it in GitHub Desktop.
set @a=null,@c=null,@b=concat("show tables where",ifnull(concat(" `Tables_in_",database(),"` like '",@c,"' and"),'')," (@a:=concat_ws(',',@a,`Tables_in_",database(),"`))");
Prepare `bd` from @b;
EXECUTE `bd`;
DEALLOCATE PREPARE `bd`;
set @a:=concat('optimize table ',@a);
PREPARE `sql` FROM @a;
EXECUTE `sql`;
DEALLOCATE PREPARE `sql`;
set @a=null,@b=null,@c=null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment