What is a "Mary Sue?" Depends on who you ask. A common belief is that this character is an "Author Avatar," or the author has placed an ideal version themselves in a story. One thing that is agreed on is that 1.) a "Mary Sue" is a character, and 2.) that the character is a "Mary Sue." Most "Mary Sues" live in the realm of fanfiction however multiple cannon characters have been labeled as a "Mary Sue" such as Bella Swann from Twilight, Lana Lang from Smallville, Eragon from well Eragon, Richard Rahl from The Sword of Truth series, and just about every superhero. For the record, I am not saying wether or not these character are "Mary Sues" or not and I purposefully picked examples from things I actually like. This is just what other people claim, I am just serving as a humble reporter.
As you may have noticed, two of these characters are male, in that case the character is either "John Doe," or "Marty Stu" depending on what article or blog you are reading. As a matter of fact, there seems to be many "Sue" categories that characters can fall into. Some involve when all the characters in the story are completely in love with the "Sue" for no apparent reason and if there are any characters who dare dislike this "Sue" then they are horrible for doing so. Another form is where this "Sue" has super-powers in a world where there are none, is a doctor for his/her day job, the most beautiful person in town, has no faults, and has modeled when they are not saving the world with their super-powers or lives using their medical training.
Here's something that really interests me. The label is "Mary Sue," thus meaning a female character. As a matter of fact, it seems that the majority of characters who are accused of being a "Sue" are females. Why is this interesting, the original "Mary Sue" was a male! The first character to receive the label "Mary Sue" was in fact a female character in an infamous piece of Star Trek fiction. However, many believe that this "Mary Sue" was written about to make fun of the male Star Trek character of Wesley Crusher.
So here's the question. How, as an author, do you avoid your character from being a "Mary Sue"? Easy, take a test! Okay, so it's not that easy and no "Mary Sue Litmus Tests" is the know and be all of "Mary Sues." Apparently, real people have gotten scores that qualify them as "Mary Sues." I don't remember where I read that, but I do remember that poor Bono is a "Mary Sue" according to these tests.
So, what else can you do? Ask the audience! Or not. I'm fairly certain, if you searched hard enough, you would fine at least one blogger who has labeled the characters you hold dearest to your heart as a "Mary Sue." I can vouch on that, I've seen people accuse every female character from every popular YA series as a "Mary Sue." Do I think Annabeth Chase from Percy Jackson or Clary Fray from The Mortal Instruments are "Mary Sues?" Not a chance, does someone else. Of course they do!
We are back to where we started. How do I avoid my character from being a "Sue"? Easy, give them depth, make the reader think they could call the character on their cell phone (if such a thing exists in that character's world) or hang out they seem so real. How does one give a character depth? Give your character faults, have them make mistakes. No one is perfect in real life so how fun would it be to read about a perfect character? Could you really relate to a "perfect" person? I know I wouldn't be able to. Still, this may not be enough. Having read Twilight and the Inheritance Cycle, I know for a fact that both Bella and Eragon have their faults and make mistakes yet they are both commonly labeled as "Sues." So I guess the real key here is to not get popular. In all reality, the more realistic your character is the less of a chance he or she is a "Sue."
Also, do not put yourself in a story. There are no inflexible rules to writing and I'm sure there are examples of an author putting themselves into their book and everything turned out fine. But it is just a good idea to resist the temptation and have the character be their own person, who is like you in ways, and unlike you in ways.
Here is a great link about "Mary Sues" which included categories and examples. Warning though, this site does use some bad language at times.
And just in case you want to give your character a "Mary Sue" test here are a few links to that. Remember, just because they score high on this does not mean that character is a waste. There are many claims that these test are biased against fantasy because of questions like "Does this character have an exotic name," or "Does this character have powers"? Only answer yes if this only applies to the character taking the test not all in the world this story takes place.