I recently started playing the Bass and my teacher gave me an exercise to practice stretching my fingers. The exercise is that I should put my pointer finger on the 5.fret and my pinkie finger on the 8.fret. My problem is that every time that I do this exercise my hand and my thumb are starting to hurt. Are there some tips for helping with this?
Try the same exercise, but at 7th and 10th fret (or any higher combination), and then move down one fret at a time when it no longer hurts your thumb.
Also, ask your teacher why you need this exercise. Is it essential for the type of music you want to learn to play? (personal note: I've been playing bass for 40 years, and never bothered with this type of exercise. My fingers haven't dropped off yet, and I haven't found a note I can't physically play...)
First and foremost, you are most likely trying to strangle the neck. Don't pull on the back so much with your thumb. Secondly, stretching isn't that necessary on bass. What's wrong with sliding your hand along?
Thirdly, you need to be asking your teacher, and if they convince you it's all needed, all well and good, listen. But actually, that stretch isn't too bad, and if it's too much, your teacher should start you on, say, fret 8 to fret 11. Unless he's anchored to playing in A. Some are!!
The process of moving from one fret to another (on the same string) doesn't have to incorporate leaving both fingers on the appropriate frets. Nice if you can, but so what if you can't? A bit of sideways movement isn't really going to marr your playing with some practice.
If the tips of your fingers are sore that is one thing. You will develop calluses. If your hand hurts, that is bad. You may be damaging your joints and this may lead to arthritis eventually.
Your teacher may be a good musician but may not have a good knowledge of human physiology. The size and shape of people's hands and the lengths of their fingers are all different.
Tell your teacher that it is painful and ask if your hand position is correct.
Overall hand position makes a big difference. If your are cramped up and at an angle to the strings it will be difficult. If you move it so that your fingers are at right-angles to the strings it will be easier.
Personally I would arrange trial lessons with a number of teachers. Without disclosing any names, mention the problems you are having and see what they say.
Most of what can be said is already said. I'm missing comments about the OP's pain in the thumb, which is very far from normal. I would like to look at posture, and make sure that your thumb is not curving above and over the upper edge of the neck (maybe that's what Tim was suggesting with "strangling the neck"). The thumb should ideally be pointing towards the headstock, around the middle of the neck. Otherwise you're forcing the thumb muscles to stretch on top of the already stretched fingers.