Obesity is associated with cervicalgia and low back pain (LBP), but the specific role and how to reduce the risk of neck pain and low back pain are not clear. The Mendelian randomization analysis was used to investigate the causal relationship between obesity and cervicalgia and LBP, as well as the effect of possible mediating factors. Then, causal associations were estimated using sensitivity analysis. Educational level (odds ratio (OR) = 0.30, 0.23) was negatively associated with cervicalgia and LBP; Heavy physical work (HPW) (OR = 3.24, 2.18), major depression (MD) (OR = 1.47, 1.32), body mass index (BMI) (OR = 1.36, 1.32), and waist circumference (WC) (OR = 1.32, 1.35) were positively associated with cervicalgia and LBP; Leisure sedentary behavior (LSB) (OR = 1.96), smoking (OR = 1.32), and alcohol intake frequency (OR = 1.34) were positively associated only with LBP, but not with cervicalgia. Ranked by mediated proportions of selected mediators, the largest causal mediator from BMI and WC to cervicalgia was educational level (38.20%, 38.20%), followed by HPW (22.90%, 24.70%), and MD (9.20%, 17.90%); However, the largest causal mediator from BMI and WC to LBP was LSB (55.10%, 50.10%), followed by educational level (46.40%, 40.20%), HPW (28.30%, 20.90%), smoking initiation (26.60%, 32.30%), alcohol intake frequency (20.40%, 6.90%), and MD (10.00%, 11.40%). For obese individuals, avoiding HPW and maintaining a stable mood may be an effective approach to prevent cervicalgia; Additionally, reducing LSB, avoiding HPW, quitting smoking and drinking, and maintaining a stable mood may be an effective approach to prevent LBP.