The important thing to know is that mediocre always has a negative connotation. You usually use it to be critical, and it would be very rude to say that to someone. "He lived a mediocre life" means he didn't achieve much, and/or was boring.
Moderate is generally positive, but it changes meaning a little. In "He lived a moderate life." It would usually mean that he did not drink excessively, wasn't wasteful, and generally behaved well.
In numerical terms, it means more what you possibly thought it did - something average.
So: His grade is moderate means he did as expected, or possibly a bit better.
His grade is mediocre means he didn't do as well as expected, but not really bad.