Diagnosis
That mildew smell is common in high-efficiency washers. It's caused by soap scum, minerals, and moisture trapped in the hidden parts of the drum and tub, especially the rubber gasket at the top (if your model has one) and the dispenser.
How to Fix It
Don't just run a bleach cycle. Here's the shop-teacher method: 1) Run a clean washer cycle with hot water (if available) and two cups of white vinegar. Let it agitate for a few minutes, then pause the cycle and let it soak for an hour. 2) Restart the cycle to drain. 3) Wipe down the entire inside of the drum, the lid, and especially the rubber seal around the top opening with a vinegar-water solution. 4) Leave the lid open after every wash to let the interior dry out completely.
If That Didn't Work
For persistent smells, check and clean the detergent and fabric softener dispensers. Pull them out (they usually snap out) and wash them in the sink. Mold can grow in the stagnant residue there.
Heads Up
Using too much detergent, especially HE detergent, is a major cause of this. It creates excess suds that don't rinse fully, leaving a film that smells. Stick to the line in the cap, and consider using even less if you have soft water.