to learn something useful about life from an unpleasant experience.
I'm never going to mix my drinks again - I've learnt my lesson.
learn (one's) lesson
To learn through painful experience not to do something, often something one had been warned about or knew might be risky. I told you that you'd feel awful if you drank that much wine. I hope you've learned your lesson.I certainly learned my lesson about buying something from a stranger online.
learn your ˈlesson
learn what to do or what not to do in the future because you have had a bad experience in the past: I used to carry a lot of money on me, until one day my bag was stolen. Since then, I’ve learned my lesson.