Thank you for the query.
Such symptoms most likely are caused by anal fissure
. This condition is caused by rectal mucosa tear(some kind of wound). That is why you feel pain while the stool irritates this wound.
To have it treated you should first of all make your stool soft. To do that, you should increase fiber rich products and mineral water intake. Physical activity should be also increased. Sitz baths with Quercus Cortex
should also help. TO ease the pain you can use hemorrhoids suppositories with lignocaine.
Hope this will help.