Try to avoid mysql has gone away errors by setting wait_timeout.