The mildew smell is from water sitting in the machine. If it's a front loader, leave the door open between loads. If it's a top loader, you can do the same. Either way there'll be water left in the basin that you can't see that will cause this.
For fun, look at the drain hose and drain pipe. If the place the hose enters the wall is too far from the floor, like more than 30", it might be hard for the washer to pump out enough water. Also, if the hose is corrugated/ribbed, it may be building up crud inside.
For 2 y.o. clothes, try a borax prewash. 1/4C powdered borax in warm water in a 5 gallon plastic bucket. Let soak an hour or two, agitate, drain, add to wash.
But it sounds like not a very good washer.