Both are absolutely stellar games and, truth be told, I consider them a single game.
Galaxy 1 was a Mario game for everybody, new to the series and old timers like myself. It wasn't mind-numbingly hard, but it wasn't too easy. It was an incredible game and I loved every minute of it - I just wished it were a little bit harder. Along, then, comes Galaxy 2. In contrast, Galaxy 2 feels like a game for us, the old timers. It was brutally difficult at times and was just as wonderful as the original game.
Thus the edge goes slightly to Galaxy 2, even though they're both perfect games.
I liked SMG 2 better also. in fact I've hardly played the original since SMG 2 came out in June 2010.
And it certainly was more difficult, mainly four particular stars: the second crate-incinerating game (whatever it was called, lost count of how many tries it took before succeeding), the chimp's second stomp game, the chimp's second ice-skating time and of course The Perfect Run (which I think I've only completed 2 or 3 times ever).
I prefer the second one but that's because I've always been more at home with 2D installments and it follows in the vain of those. Galaxy 1 definitely had a more cinematic feel with more and better cutscenes, a larger hub world, and more expansive galaxies to explore. Galaxy 2, on the other hand, offered Yoshi for the first time in a 3D installment in nearly 10 years, an option to play as Luigi closer from the game's start, and a better difficulty gradient. Also, seeing a giant Bowser in 3D was a life dream fulfilled. I played the heck out of Galaxy 1, don't get me wrong, but Galaxy 2 seamlessly blended 2D and 3D Mario and was the precursor to Super Mario 3D Land which did so even better and cemented the existence of a third type of Mario platformer-a mixture of dimension galore.