Studies show that magnesium may help reduce various types of pain including headaches and back pain. Try eating more magnesium-rich foods and talk to your healthcare provider about taking magnesium supplements to manage pain.