A Mary Sue is one of those female characters who is basically "perfect" - often times, a much idealized version of the author. She's beautiful, she's got a sparkling personality, and everyone in the story loves her. If she has any "flaws," they are the kind that only make her more "endearing" - like, because she was abused by her alcoholic father or cheated on by her loser boyfriend, she has low self-esteem and doesn't realize how beautiful she is. Barf.
I guess the best way to avoid Mary Sue territory is to try and create a character who seems like a real person... but ISN'T a real person, a la yourself LOL. You have to remember that even pretty people aren't flawless, and usually have personality flaws to make up for their lack of physical ones. So give your character flaws - real flaws. Annoying flaws, even. Of course, you want her to be likeable to your readers, but you also want her to be interesting, and perfect isn't real or interesting.
The problem is, there's no exact formula for creating a great character. It's not a science; it's an art. It takes the right character traits, combined with the right story and style of writing, to create the magic of a truly good character. Even for the best of writers, it doesn't happen with every character.