Being mean is a sign of insecurity, of needing attention (albeit negative attention), of jealousy and internal misery. People who are intentionally mean to others do so out of a sense of the world not being fair to them so they strike out at others who "seem" to have it all together. They turn their internal misery outward and blame others for their sense of insecurity and negative circumstances.
One of the best ways to deal with mean people is not to personalize it. When people are mean to you try to understand that they are just miserable with their own lives and circumstances and are just using you for target practice. I have begun to see that when people treat me badly and, while I understand that it is not directed at me personally (even though I am the one being attacked), I choose to try to help them if they will let me. Sometimes that is a feat in itself, but I love it when that works out. However, if I am not able to help them despite all of my efforts, the last thing I do is to get them out of my life and keep them there. There is no reason to have to constantly deal with mean and negative people who refuse to change.
Taylor Swift has a great song out called, "Mean." I love the lyrics in general, but especially these in the middle: