As a noun, anodyne is something, usually a drug or medication, that relieves hurt or pain. It can also be something that relaxes or comforts.
As an adjective, anodyne describes something or someone as inoffensive, benign, or mild. It also can relieve pain.
Analgesic, which is the same in its noun and adjective forms, is strictly a medical term for drugs that alleviate pain. It comes from the word analgesia, another medical term for the lack of ability to feel pain while still maintaining consciousness.
In short, when in the medical field, these words are synonyms. When one is discussing things other than medication, anodyne is the preferred.
Examples
Back at the England and Wales Cricket Board in London, they would have been choking on their anodyne official statements. [The Independent]
They viewed the government’s recommendations of improved training, procedural reform and culture-changes as too much anodyne bureaucratic talk, and not enough action. [BBC News]
The seed, stem and roots have been reported to be effective as a cough suppressant anodyne, as well as an aphrodisiac and hypoglycaemic agent in treatment of diabetes. [The Guardian]
Produced in clandestine laboratories, the drug is a potent synthetic opioid analgesic that can appear in the form of pills or powder. [Edmonton Sun]
The symptoms could be applied to those under the influence of elephant juice (etorphine), another AJC lab triumph detecting the powerful narcotic analgesic for the first time in 1987. [Sydney Morning Herald]