Guardiola pleased with Bayern response
Shawn Parker's goal a minute before the break stunned Guardiola's men, but two goals in two minutes from Arjen Robben and Thomas Muller shortly after the interval turned the game on its head.
Mario Mandzukic added a third in the 69th minute before Muller scored his second from the penalty spot eight minutes from time to send Bayern a point clear at the top of the Bundesliga.
"I am delighted with the result," Guardiola said. "In the first half here at the Allianz Arena we always have problems, but I am sure that we will improve in a short time.
"I remained calm at half-time - we changed the system a bit and then Arjen (Robben) played on the left."
Captain Philipp Lahm echoed the sentiments of his coach, before going on to praise their opponents.
"In the first half we played a bit without focus," the Germany full-back said. "This is often a problem after the international break and we need to get to grips with this as quickly as possible.
"We changed something (at half-time) and that has borne fruit. Credit must go to Mainz, they made our lives difficult."