A Mary Sue (for female characters) or Gary Stu / Marty Stu (for male characters) is a character who effectively stands in for the author and acts as a form of wish fulfillment. This type of character is most often inserted into amateur fiction that takes place within an established narrative. For example, "Emily was a new student at Hogwarts. She was intimidated by all of the young wizards and witches around her; but when she saw Prof. Snape her heart skipped a beat . . .". While there is nothing inherently wrong in wish fulfillment fantasies, in published literary works it is often seen as a hallmark of an amateur.
[Edit 5/7/2015 10:55 AM EST] +A. Miles Davis brought up a good point and I would like to add it to the definition.
The issue with a Mary Sue character isn't the part where you're putting yourself into the story. It's the part where you're better than everyone at everything within that story without an actual reason to be; that all attention focuses on that character to the exclusion of proven experts; and there is a false pretense of modesty about it.Batman, for example, doesn't fall under this trope due to the actual training he puts himself through to become an expert in his field of Batmaning. There are things he cannot do, he has limits (and sometimes will admit so), and doesn't prance about "accidentally" solving crimes.Bella Swan, as a counterexample, is a useless lump of nothing that everyone inexplicably wants and is treated as this perfect thing, to the point where she has a vampire-jesus-baby.
[Edit 5/7/2015 12:56 PM EST] +Dan Head had some additional thoughts on the subject of the Mary Sue that I felt should be included:
1. Every author puts themselves into every story. So does every reader. This is why writing is inherently personal, and also why two readers take different messages from the same works. The idea that "only" amateur authors put their own hopes/dreams/fears into their work is totally at odds with reality.2. The issue with a Mary Sue (I hate that term) is that it's a viewpoint character around which the whole plot revolves for no good reason. An excellent example is in the current season of Agents of SHIELD. Skye is our viewpoint character. Like her or not, this is okay. What's problematic is when OTHER CHARACTERS' arcs revolve around their unaccountable fixation with the audience surrogate, Skye. Specifically, Fitz & Simmons have had an interesting relationship dynamic independent of Skye. But sometimes the writers fall into the trap of having them obsess about their relationship with Skye in context of their relationship with each other, and it's just bad writing. It's putting the AUDIENCE SURROGATE (not the writer's surrogate) into the center of every plot point, especially when it's transparently because the work itself is escapist. So the audience surrogate HAS to be there, or else the audience isn't escaping.3. Writers write. Those who can't spend time calling stuff a "Mary Sue". Writing is hard. It's also imperfect. This is not news.