According to the data you provided, you might be experiencing hemorrhoids.
Hemorrhoids are swelling and inflammation of veins of the rectum and anus. The inflamed tissue can exit through the anus. This can make the defecation painful. Also, when defecating, the feces might additionally hurt the tissue causing bleeding.
However, you might want to visit your family doctor to have him examine the hemorrhoids and to rule out possible more serious conditions.
If hemorrhoids are confirmed, anti-inflammatory cream might temporarily relieve the symptoms. For permanent solution, surgery might be needed.