Andy Murray beat Florian Mayer for his 400th career win to advance through to the third round of the Madrid Open.