I would argue having a firearm is unlikely to help. At close range, knife has the advantage and you probably won’t even get the gun out. At longer range, running/avoiding is a better choice if you can.
There’s a few YouTube channels that I think do a good job of being level-headed when it comes to analysing self-defense and giving decent advice around it. Hard2Hurt, Armchair Violence (a more general channel that recently did a video on unarmed knife defense), and Active Self Protection are three that come to mind right off the bat. All three say the same thing: • avoid sketchy locations if you can • pay attention to the people around you, especially in what are called “transition areas” like when you walk out of a store • deescalate conflict as much as possible (without giving in to demands) • leave as soon as you’re able • only fight when your hand is forced
As far as I’m aware, they all also advocate for carrying pepper spray and participating in folkstyle wrestling to use as your defensive base for things that don’t require lethal force. The problem is, you don’t have the only say on whether a situation will become a threat to your health and safety or not. Sometimes you’re just unlucky and a guy flips out on you for something petty and now you’ve got a guy pushing and shoving yelling about how he’s gonna fuck you up and you can see a pocket knife clipped in his pocket.
Most firearm uses are at very close range. If you practice your draw—and you absolutely fucking should—you should be able to draw and fire multiple rounds with a person busy punching or stabbing you. (Through what usually happens is the victim manages to get a window of separation and uses that to draw their weapon.) After a few shots your attacker will have had enough time to react to what you’re doing, but most people react to being shot in the gut by falling over. It’s mostly a psychological thing, but surprisingly effective. Once they do that, turn and run. All you’re trying to do is get them to stop hurting you so you can get away safely.