Skip API key check more robustly in case of database downtimes.

The mapping from `pymysql.exc.OperationalError` to
`sqlalchemy.exc.OperationalError` doesn't always work reliably.
Extend db ping to retry connections for `2003 connection refused` errors.