[1.7.x] Fixed #23089 -- Fixed transaction handling in two management commands.

Previously, when createcachetable and flush operated on non-default
databases, they weren't atomic.

Backport of 753a22a635 from master