Mma for street defense

I hope this question complies with the rules of this forum.

What is the way to feel more safe and prepared in case of aggression in the street?

I live in a somewhat dangerous city and I would like to learn a minimum of how to defend myself (or at least how to throw a punch). The first rule is to avoid the fight and run away, but sometimes it is not like that.

I want to take some private boxing/mma lessons and buy a bag at home, starting to train constantly. Do you think it could be useful?

I fear that the only way to know how to defend yourself is to train with someone in a ring or to have had experiences on the street (wanted or not). What do you think?