Skip to content

Instantly share code, notes, and snippets.

@agiannis
Last active April 19, 2016 16:27
Show Gist options
  • Save agiannis/89fd946e7b5dc732b46f to your computer and use it in GitHub Desktop.
Save agiannis/89fd946e7b5dc732b46f 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