[1.6.x] Fixed #23089 -- Fixed transaction handling in two management commands.
Previously, when createcachetable and flush operated on non-default
databases, they weren't atomic.
Also avoided transactional DDL and transactional truncates on databases
that don't support them (refs #22308).
Backport of 753a22a6, 0757e0f3, and 6877a9d4 from master