As per your details, I suspect you are suffering from Anal fissure, though clinical examination is always appreciated.
For relief:-
Have a stool softener like Syr. Cremaffin plus~15ml before sleep
Do Sitz bath with lukewarm water (take warm water in a tub and sit in it) 3-4times daily
Apply Anobliss/Anomed-L ointment after every Sitz bath and before passing motion
If pain is severe, then have some oral pain killer otherwise no need
Next Steps
It will be better if you visit a Surgeon or Proctologist for clinical evaluation and better opinion
Health Tips
Have plenty of oral fluids and fibre rich, non-spicy diet
Avoid heavy meat in diet