Thanks for coming back.
Right, in populated areas, when mining, pirates will show up. It's normally the case that as soon as you enter the ring, they flick up on your radar. I normally take that time to sort my hard points out, boost toward the rocks, you know, get ready. I might fire off a prospector if I get to a rock soon enough, but I always wait. The pirates will swing by, tell me about hungry children then go. Now I can mine.
If I leave that ring then decide to go back in it, that dance is going to happen again. Except this time, I have cargo.
Depending on your ship and skills, you could try boosting away, but for me, I never go back in. Once out of the ring, I slam the pedal down and get to where I'm going. Your mistake here has been to go back into the ring, holding cargo.
So either don't do that again or next time you're ion some rings, on your own, have a trial run at how you might boost your way through the rocks and get out of the ring.
What ship you in?