For my purposes a Mary Sue is a blatant authorial self-insert in place of another character, and no more. When detailing this fault it's rather easy to confuse things by wandering off into a discussion about characters and characterization. Then any perceived failing of how a character is presented gets mislabeled as a Mary Sue.
Stephen King is the most well known to be consistently called out on this. While King bashing is a popular pastime for the greater /lit/scape, this is one accusation that is consistently wrong. So he's worth some study to see how he doesn't do this.
Some part of yourself will intrude into each character to some extent, that's not a surprise. One way to avoid stomping the character is to decide what you would do or say in a given situation, and have the character do something, anything, else.
I think a good study here is the character Pinkie Brown in the novel "Brighton Rock" by Graham Greene. I get the impression Greene built Pinkie with this method, having him do the exact opposite in any given situation.
Another issue is dialogue. You need to learn how to have a character speak differently than you do. One cheap trick here is to listen to and analyze your own speech. Identify the vocabulary and patterns you use, and never let a character use them.
Take some acting classes, and/or read up on acting methods.
On the other hand, stories with authorial self inserts can work just fine. Roman à clefs are a thing. See pretty much any Bukowski novel, or "Two Sisters" by Gore Vidal. The key here is that the audience understands what you are doing and who you are within the story.