Gracefully close mysql thread to prevent overloading