Whether it’s a nagging backache or a pounding ­migraine, the search for relief can be frustrating.

In a nationally representative Consumer Reports survey of 3,562 people with back pain, more than half said they saw two or more professionals and tried five or more treatments to find relief, including prescription and over-the-counter drugs.

Some people with pain end up using medications that can cause bothersome effects or pose risks. Case in point: 57 percent of the back-pain sufferers in our survey who said they used prescription drugs turned to powerful opioids.

These can alleviate severe pain after surgery or serious injury. But the Centers for Disease Control and Prevention says that taking them for longer than several days can do more harm than good, increasing the risk of addiction and overdose.

A study published in April in the journal JAMA Surgery found that 6 percent of people who were prescribed opioids after surgery were still taking the drugs three to six months later. That amounts to an estimated 2 to 3 million surgery patients each year, says the lead author, Chad Brummett, M.D., director of pain research at the University of Michigan Medical School.

“Our data suggest that most patients are not better after having taken long-term opioids,” Brummett says. “In fact, many are worse off and report increased pain and poorer sleep.”

Though generally considered safe, nonsteroidal anti-inflammatory drugs, or NSAIDs, which are available in prescription and OTC formulations, can slightly increase your likelihood of heart attack or stroke. The Food and Drug Administration recently warned that people at greatest vulnerability are those who’ve had a heart attack or have heart disease.

So how can you get the relief you need and minimize your risk of side effects? Here, from our CR Best Buy Drugs experts, is a guide to the most common types of pain pills and how to use them, plus how to alleviate pain without meds.

Acetaminophen

Acetaminophen (Tylenol and generic) is available OTC.

Best use: For mild to moderate pain, such as headaches and osteoarthritis (OA). Though not as effective as OTC drugs such as the NSAID ibuprofen for most pain, acetaminophen is gentler on the stomach, and that makes it a good ­option for people with acid reflux or ulcers, according to an analysis by Consumer Reports Best Buy Drugs. It also won’t ­increase heart attack and stroke risk, as NSAIDs may.

Safety smarts: Our experts recommend no more than 3,250 mg, or 10 325-mg pills, in a day. Taking more or mixing them with alcohol can damage your liver.

Important to know: In rare cases, acetaminophen can cause serious skin reactions that could include blisters or a rash. If that occurs, stop taking it and seek medical attention immediately.

Anti-inflammatory Medications

NSAID pain relievers are available in OTC and prescription-­strength versions of aspirin (Bayer, Bufferin, and ­generic), ibuprofen (Advil and generic), and naproxen (Aleve and generic). Prescription-only meds include cele­coxib (Cel­ebrex and ­generic) and diclo­fenac (Cambia, Voltaren, and generic).

Best use: For mild to moderate pain such as headaches, migraines, and muscle aches, and to manage OA. If an OTC NSAID doesn’t bring you relief, your doctor might prescribe a higher-dose version.

Safety smarts: Whether you’re using an OTC or a prescription NSAID, take the lowest dose for the shortest period of time—and not for longer than 10 days for pain without talking to your doctor. If you find yourself using OTC NSAIDs three or more times per week, ask your doctor about other pain-relief options.

NSAIDs can hike the risk of stomach and intestinal bleeding and ulcers, particularly when used regularly in high doses. Don’t combine NSAIDs with each other; together they can boost the risk of ulcers and gastrointestinal (GI) bleeding.

Note that although most NSAIDs ­increase heart attack and stroke risk a bit, aspirin has been shown to lower it. So if you have heart disease or risk factors for it, talk to your doctor about what’s appropriate for you.

Important to know: Alert your doctor if you have burning stomach pain or bloody, black, or tarry stools—signs of GI bleeding. If you have GI bleeding or ulcers (or you’re at risk for the condition), ask your doctor about low-dose NSAIDs or acetaminophen.

Opioids

These prescription drugs include fentanyl (Actiq, Abstral, Duragesic, Fentora, Onsolis, and generic), hydrocodone (Vicodin and generic), and oxycodone (OxyContin, Percocet, and generic).

Best use: For severe acute pain after surgery or from injuries, such as those sustained after a bad fall or car accident.

Safety smarts: Start with the lowest dose possible and use for only a few days. (Even short-term use can cause such side ­effects as abdominal cramps, constipation, headaches, nausea, sleepiness, vomiting, and a fuzzy-headed feeling.) If your pain persists after a few days, talk with your doctor about non-opioid alternatives, including nondrug approaches.

Taking these drugs for longer than about three days can hike addiction and overdose risks, and their effectiveness can diminish over time. So you might need ever-higher doses for relief. Opioids can also impair your immune system’s functioning and heighten pain sensitivity.

Important to know: For dental problems, such as post-extraction pain, research shows that OTC pain relievers work just as well as—or better than—opioids for most people, with far fewer side effects.

Muscle Relaxers

These prescription drugs include cyclobenzaprine (Amrix, Fexmid, and generic), metaxalone (Skelaxin and generic), and carisoprodol (Soma and generic).

Best use: For acute, severe neck or back spasms; muscle spasticity associated with cerebral palsy, multiple sclerosis, or a stroke; or if you have liver disease and can’t tolerate OTC painkillers.

Safety smarts: Muscle relaxers can cause sedation and be addictive, and most studies show that they are only marginally effec­tive. Carisoprodol, for instance, poses a high risk for abuse and addiction. So most people are better off skipping them.

For the few exceptions where muscle relaxers are a preferred option, take them for no longer than three weeks—less, if possible. Using them every day or long term for persistent types of pain, such as lower-back pain and joint pain, isn’t recommended. Studies have failed to show that muscle relaxers work well for chronic pain.

Important to know: If you’re 65 or older, steer clear of these because they’re associated with an increased risk of falling.

For some, the safest ways to ease pain might be nondrug treatments, such as yoga, tai chi, and massage.

Stop Discomfort Without Drugs

Nondrug treatments such as exercise, behavioral therapy, and massage can reduce pain and increase your ability to function. But not all nondrug treatments are appropriate for all types of pain. So check with your doctor before you try a nondrug therapy, and ask whether he or she can recommend a trusted practitioner. Some options to consider:

Back pain. Gentle movement—such as swimming, tai chi, walking, and certain forms of yoga—has been found to be helpful. Acupuncture, massage, physical therapy, and spinal manipulation (preferably by a chiropractor or an osteopathic physician) are good options as well.

Headaches. Cutting back on alcohol and avoiding foods that seem to trigger headaches could benefit you. So can controlling stress with meditation or relaxation therapy. Certain studies suggest that aerobic exercise, such as cycling, might reduce migraine frequency and intensity.

Osteoarthritis. Low-impact exercise, such as walking, biking, and yoga, can ease pain and improve your ability to function. But avoid high-­impact activities, such as running and tennis. They could aggravate your symptoms.

Fibromyalgia. Regular tai chi and restorative yoga, which ­involve slow, gentle movements and deep breathing, might help reduce pain and fatigue. Cognitive behavioral therapy and meditation are also good choices.

Editor's Note: A version of this article also appeared in the August 2017 issue of Consumer Reports On Health.

These materials were made possible by a grant from the state Attorney General Consumer and Prescriber Education Grant Program, which is funded by a multistate settlement of consumer fraud claims regarding the marketing of the prescription drug Neurontin (gabapentin).