Resolve shutdown crash/leak if MySQL server is not running

Fixes #12734