Mould/mildew stains are virtually impossible to remove. You can kill the mould but it will still be visible in most cases. Occasional success though with H2O2
Unless it's a 100% polypropylene pile carpet. You can use perhaps a 50/50 mix of household bleach and water. Just enough to wet the pile, dwell a little then freshwater rinse, repeat as required. Very nasty stuff, DO NOT mix or rinse with other chems, gloves and mask etc.
Ventilate, disclaimer and great care.
SAFE and happy cleaning

Ken