Matt Cain threw a one-hitter, allowing only a single by Pittsburgh pitcher James McDonald in the sixth inning during a near-perfect performance Friday as the San Francisco Giants beat the Pirates 5-0 in their home opener.

Cain struck out 11 and permitted just a single runner. McDonald, a career .069 hitter coming into the game, hit a sharp single to left field with two outs in the sixth inning.

Fans in the sellout crowd of 41,138 jumped to their feet to give Cain a warm ovation.

Cain (1-0) pitched his third career one-hitter, his fifth shutout and his 14th complete game.

Aubrey Huff homered as the Giants returned from a rough road trip. Buster Posey hit an RBI double in his first regular-season game at AT&T since his season-ending collision at the plate with the Marlins' Scott Cousins last May 25.

The Giants celebrated their 1962 World Series team and a large cast of Hall of Famers with an impressive day — with blue skies and sun to boot after a huge rain and thunderstorm overnight and into Friday morning threatened to mess with the festivities.

Cain, who has long been the team's hard-luck loser because of a lack of run support, went the distance in throwing 106 pitches. Closer Brian Wilson wasn't available after he worked a 32-pitch ninth inning a day earlier in a 4-2 win at Colorado.

Pitching 11 days after signing a new $127.5 million, six-year contract, Cain worked ahead all afternoon and faced only one three-ball count while retiring the first 17 batters in order.

McDonald produced his seventh career hit but Pittsburgh dropped its fourth straight game after being swept at Dodger Stadium.

McDonald (0-1) allowed three runs on six hits in 5 2-3 innings, struck out one and walked three.

Huff hit a two-run homer in the eighth. Nate Schierholtz had a pair of singles and drove in a run in the sixth for the Giants, who came home from a 2-4 road trip in which they were swept in three one-run losses at defending division champion Arizona before taking two of three from the Rockies at Coors Field.

Posey wound up 1 for 3 with the double and a walk in his long-awaited home debut in front of the fans who have supported him every step of the way in his long journey back from three torn ligaments in his left ankle and a broken bone in his lower leg.

The day began with a special tribute to the '62 World Series team 50 years later, a roster that fell just short in seven games to the New York Yankees despite having Hall of Famers Willie Mays, Willie McCovey, Orlando Cepeda and Gaylord Perry. They were among those to attend.

Tyler Stow, the 13-year-old son of beaten Giants fan Bryan Stow, threw out the ceremonial first pitch in place of his dad. Bryan Stow, sitting in a wheelchair accompanied by his mother, Ann, was shown on the main center-field scoreboard as if handing the ball to his son while wishing the boy good luck.

NOTES: Cain's last shutout came on June 8, 2010, at Cincinnati. It also marked the third time he pitched a shutout allowing only one hit. ... Struggling San Francisco 1B Brandon Belt didn't start for the fourth straight game. He's 1 for 11 with five strikeouts in four games. ... San Francisco manager Bruce Bochy said Wilson would be ready to go for Saturday night. ... The Giants sold out for the 85th straight time, a streak that began with the final three regular-season games of 2010. ... Garrett Jones played his first game of the season in RF for Pittsburgh. ... The Pirates will need to make a roster move Saturday if Charlie Morton comes off the disabled list to start.