* TSX ends up 165.06 pts, or 1.3 pct, at 12,623.36
* Highest close since Sept. 8, 2011
* Greek debt deal lifts risk appetite
* Domestic economic data mixed
By Jon Cook
TORONTO, Feb 21 (Reuters) - Canadian stocks surged to a five-month high on Tuesday, with mining and oil shares leading the way, as risk appetite grew after euro-zone finance ministers sealed a bailout package for Greece.
The 130 billion euro ($172 billion) deal was finalized after euro-zone officials forced Athens to commit to unpopular cuts and as private bondholders agreed to accept deeper losses. It means Greece will not default on 14.5 billion euro in bond redemptions due next month.
"This is about taking the downside risk off the market, but it doesn't give you the upside part of the equation," said George Vasic, equity strategist and chief economist at UBS Securities Canada. "It's got to be sustained by good (global) economic data."
The Toronto Stock Exchange's S&P/TSX composite index finished up 165.06 points, or 1.3 percent, at 12,623.36, its biggest one-day gain since Jan. 3 and its highest level since Sept. 8, 2011.
Signs that Europe's debt crisis is being stabilized and of health in the U.S. recovery have rallied the TSX more than 5 percent so far this year.
In the United States, the Dow touched 13,000 on Tuesday for the first time since just before the financial crisis took hold in 2008.
Nearly all of the TSX index's 10 main sectors were higher, led by the heavily weighted materials group, which gained 3 percent.
Gold miners led the way, with Barrick Gold up 3 percent at C$48.25 as the world's top gold miner rode higher bullion prices. Goldcorp climbed 2.9 percent to C$48.16 and Yamana Gold Inc jumped 4.5 percent to C$17.13.
Base metal miners also rose as investor appetite for risky assets such as industrial metals increased. Gains were led by First Quantum Minerals, up 3.7 percent at C$23.06, and Teck Resources, which rose 3 percent to C$39.44.
Potash Corp, the world's largest fertilizer producer, climbed 2 percent to C$46.88 on hopes that a more stable European economy would help global demand.
Oil and gas shares pushed up 1.4 percent as oil prices rose on heightened euro zone optimism and on stricter sanctions against Iran. Suncor Energy was the biggest heavyweight gainer, rising 1.8 percent to C$34.74.
Oilfield services company Flint Energy spiked 66 percent to C$24.79 after U.S. engineering company URS Corp said on Monday it will buy it for C$1.25 billion ($1.25 billion) in cash.
Flint's pending acquisition boosted shares in other Canadian construction companies that are active in the oil and gas sector. Aecon Group, for instance, jumped more than 8 percent to C$12.44.
Financial stocks lagged the TSX index's gains, but still climbed 1 percent. Royal Bank of Canada led the group, rising 1.1 percent to C$53.72.
The Greek euphoria overshadowed some mixed Canadian data on Tuesday. Retail sales dropped for the first time in five months in December, though wholesale trade rose in the final month of last year.
"These numbers look weak in relation to the first half of 2011, but we knew Canadian consumers have been a little more prudent so it's not entirely surprising," said Carlos Leitao, chief economist at Laurentian Bank Securities.