learn a lesson
also learn your lessonto understand something because of an unpleasant experience, esp. when this means you will not do it again:
My computer crashed before I saved the document – I've learned my lesson, and now I save everything all the time.