The first thorough examination of President John F. Kennedy's medical records, conducted by an independent presidential historian with a medical consultant, has found that Kennedy suffered from more ailments, was in far greater pain and was taking many more medications than the public knew at the time or biographers have since described.

As president, he was famous for having a bad back, and since his death, biographers have pieced together details of other illnesses, including persistent digestive problems and Addison's disease, a life-threatening lack of adrenal function.

But newly disclosed medical files covering the last eight years of Kennedy's life, including X-rays and prescription records, show that he took painkillers, antianxiety agents, stimulants and sleeping pills, as well as hormones to keep him alive, with extra doses in times of stress.

At times the president took as many as eight medications a day, says the historian, Robert Dallek. A committee of three longtime Kennedy family associates, who for decades refused all requests to look at the records, granted Mr. Dallek's, in part because of his ''tremendous reputation,'' said one of them, Theodore C. Sorensen, who was the president's special counsel.