27 year old bass player here, who has had neck and shoulder pain from almost as soon as I began playing the bass.
Obviously technique, good playing habits, and GOOD POSTURE are all very important: focus on eliminating tension and economy of motion.
But the instrument is a beast to handle; it's easy to be tense when there's eleven pounds hanging from your neck.
I have experienced a lot of pain and outright repetitive stress trauma that has taken two and a half years of physical therapy to deal with.
If you are going to be practicing or performing bass for 2-6 hours a day like a pro or student will, there's an essential routine ingredient no one has mentioned yet:
You ABSOLUTELY NEED a strength-building workout routine. Lifting free weights (barbels are good for your arms, but medicine ball is my favorite because it really gets your whole core-torso-arm-wrist-finger system engaged and coordinated) is a popular choice. Calisthenics can give excellent results, too. The important things to focus on are; core stability; ligament, joint, and muscle strength; and flexibility.
Some easy things to start with:
Pushups & variations
Pullups
SHOULDER PRESS!!!
Squats and lunges
If you have access to some sort of bar suitable for deadlifting, that made a big difference for my spinal-axis health.
Honestly those hand spring squeezer devices are...... they're pathetic and misguided. Grip strength is good but you never want to SQUEEZE a barbel or your bass neck.
You're looking for exercises that are the exact opposite of resistance training on a weight machine that isolates one muscle group.
You don't need really "cardio" like running but my favorite, because of their benefits to your posture, are the stairmaster and rowing machines.
Funny end note: If you have enough space to swing it (SLOWLY) around freely, using the bass guitar sort of as if it's a barbel and doing (SLOW) range of motion exercises with it is honestly really effective. Hold it hanging by the end of the neck and fully extend your arm, testing it's weight and leverage. Rotate your waist and begin noticing how the bass's center of gravity affects your posture. Do similar motions while holding it from the neck-body joint. Use two hands to lift it over your head. Do shoulder presses, bicep curls, etc.
This has the added benefit of a tangible psychological effect.