Fix loop in mysql script